2022/09,江端さんの忘備録

最近、長女が、ロシアによるウクライナ侵攻を見て、真剣に国防を考え出しているようで、大変、興味深いです。

It is very interesting that my senior daughter has recently started to seriously consider national defense after seeing the Russian invasion of Ukraine.

# 正確に言うと『国防』ではなくて『逃亡』ですが。

# To be precise, it's not 'national security' but 'escape'.

―― どこに逃げればいいの?

"Where to escape?"

と、真剣に心配しています。

She is seriously concerned.

-----

「我が国(日本)が、今後、どういう流れで戦争に巻き込まれていくか」 ―― というシミュレーションは、私にとっては、大好物のネタですので、そのいくつかのシナリオを長女に語りました。

Simulations of how our country (Japan) might be drawn into a war in the future are a favorite topic of mine, so I told her about some of the scenarios.

昨夜は、これに加えて、「ロシアから見た正義」と「中国から見た正義」についても解説してみました。

Last night, in addition to this, I also explained "justice from the Russian point of view" and "justice from the Chinese point of view".

―― 彼らには、彼らなりの、戦争をしかけるだけの正当な理由がある

"They have their own, justifiable reasons for starting a war"

という私の話が、長女を、さらに不安にさせているようです。

The stories of mine seemed to make her more anxious.

それはさておき。

Aside from that.

-----

以前、私は、長女と次女の近代歴史知識の乏しさを批判し、逆に論破されたことがあります。

I once criticized my daughters for their lack of modern historical knowledge, and was rebutted.

「いや、『四人組』とか『文革』とか、嫌な話がテンコ盛りでしょう?」(2017-04-15 の日記)

実際に、歴史の教師は「歴史が重要だ」と言い続けていますが、はっきり言います―― 「古代エジプトのファラオが誰であろうか、その国が滅びようが、それが何だと言うのか」

一方、嫁さんの方は、近年「忠臣蔵」のドラマが放送されていないことに、重大な危機感を感じているようです。

On the other hand, my wife feels a serious sense of crisis over the fact that no "Chushingura" dramas have been broadcast in recent years.

『日本人から、「忠臣蔵」の精神が失われたら、どうするんだ』と。

"What if the spirit of Chushingura is lost from the Japanese people?"

私は、こちらについては、心底"どーでもいい"と思っています。

I am truly "not concerned" about this.

しかし、以前『徒党を組んだ地方浪人による、テロ事件』と語った時に、もの凄く怒られたので、黙っています。

However, my wife was extremely angry with me when I told her that it was "a terrorist attack by local ronin who formed a clique," so I have kept my mouth shut.

-----

私たちは、自分なりの価値観で、その価値観を他人にも理解して欲しいと考えますが ――

We have our own set of values, and we want others to understand those values, but--

結局のところ、そういう試みの多くは、『無駄』に終わります。

After all, such attempts will be in vain.

2022/09,江端さんの技術メモ

golangを使った、postgresqlのinsertの方法

/*

こんな感じで、DBとTableを作りました

create database agent_db;

create table LocMessage(
	ID     int,
	Lat    double precision,
	Lng    double precision,
	TYPE   varchar(10),
	POPUP  int,
	RealId int,
	PersonState      int,
	BikeState        int,
	StartStationLat  double precision,
	StartStationLng  double precision,
	GoalStationLat   double precision,
	GoalStationLng   double precision,
	StartStationName varchar(40),
	GoalStationName  varchar(40)
);

ちなみに、全部小文字になるみたいですねえ。
agent_db=# select * from locmessage;
 id |  lat   |  lng  |   type   | popup | realid | personstate | bikestate | startstationlat | startstationlng | goalstationlat | goalstationlng | startstationname | goalstationname
----+--------+-------+----------+-------+--------+-------------+-----------+-----------------+-----------------+----------------+----------------+------------------+-----------------

*/

package main

import (
	"database/sql"
	"log"

	_ "github.com/lib/pq"
)

func main() {

	db, err := sql.Open("postgres",
		"user=postgres password=password host=localhost port=15432 dbname=agent_db sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	//_, err = db.Exec("insert into locmessage(id,lat,lng,type,popup,realid,startstationlng ) VALUES(1, 139.0, 38.0, 'PERSON',1,1,222.222);")
	// _, err = db.Exec("insert into locmessage(id,lat) VALUES(a, b);")
	//ins, err := db.Prepare("insert into locmessage(id,lat,lng,type,popup,realid,startstationlng ) VALUES(?,?,?,?,?,?,?)")
	ins, err := db.Prepare("insert into locmessage(id,lat,lng,type,popup,realid,startstationlng ) VALUES($1,$2,$3,$4,$5,$6,$7)")
	if err != nil {
		log.Fatal("db.Exec Error: ", err)
	}

	a := 1
	b := 139.02
	c := 38.02
	dd := "Tomoichi"
	e := 1
	f := 1
	g := 333.333

	//ins.Exec("1", "139.0", "38.0", "BIKE", "1", "1", "222.222")
	//ins.Exec(1, 139.01, 38.01, "BIKE", 1, 1, 222.222)
	//ins.Exec(1, 139.0, 38.0, 1, 1, 1, 222.222)
	ins.Exec(a, b, c, dd, e, f, g)

}

とりあえず、これでデータベースの書き込みはできるみたい。

2022/09,江端さんの忘備録

「オリジナル原稿購読希望」をされる方が、止まりません。

The "original manuscript subscription applicants" are coming even now.

―― 『とある宗教団体』を直撃する内容

今ごろになって、『もし、期待外れだったら、どうしよう』と心配になってきました。

By now, I'm starting to worry, 'What if it's a disappointment for them?'

私は、「この内容なら大丈夫」と勝手に判断したもので、そんなに、凄い内容とは思っていなかったものなのです。

I had judged on my own that the content would be OK. and I did not think it would be that great.

(但し、編集部は"削除"を、嫁さんは"休載"を、要求する内容ではあったようですが)

(However, it seems that the editorial department demanded "deletion" and the wife demanded "suspension of publication.)

―― この教団に関する本(教義も含む)を数冊読めば、誰でも分かる程度の内容

"Enough for anyone to read a few books on this cult (including its doctrines)"

です。

―― 宗教団体のネタにコメントすると、面倒くさいことになる

(応募者が0人が、連続2日を経過した段階で、配布を予定しております) の要件が満たさていません。

(After zero applicant after two consecutive days, I will publish it. ) is not satisfied now.

この週末に編集作業を進めますが、リリースはもう少しお待ち頂くかもしれません。

I will work on editing this weekend, but may have to wait a little longer for release.

悪しからずご了承下さい。

Please understand that I apologize.

2022/09,江端さんの忘備録

最近、自分が老害の側に立っているなぁ、と実感します。

Lately, I realize that I am standing on the side of the old man, that menas, problems caused by the elderly (esp. gerontocracy, and elderly people's control over the young)

なるべく、若い人の考える発想や感性に『手を出さないように』と心がけているのですが、これが、なかなか難しいです。

I am trying not to touch youth ideas and sensibility, however, it is hard for me.

ご存知とは思いますが、私は、社会的な正しさや、常識と言われているものに対して、『本当にそうだろうか?』と疑義を呈することを、仕事のネタにしています。

As you know, one of my businesses is to make questions against the social and political correctness.

そして、その正しさや常識を、『数字』を使ってひっくり返す、という趣旨のコラムの連載を続けています。

So I continue to write a series of columns with the aim of using "numbers" to to turn the correctness and common sense upside down.

つまり、

It means,

―― (主に、若い人の考えがちな)アイデアを、その場で叩き潰すことができるだけのネタが、頭の中に満載されている

"I have a lot of logics to knock down the ideas that young people tend in my mind"

のです。

しかも、そのネタとは、具体的な数値がスラスラ出てくる、という状況です。

To make the worst, I can show them using many specific numbers.

-----

私は、自慢をしている訳ではないのです。

I am not trying to brag.

「年齢を重ねる」ということは、こういう経験や計算をする時間が「長かった」という、それだけのことです。

"Getting older" menas that I have had "more time" to have these experiences and calculation. That is all.

シニアは、生きている期間が長いだけで『強い』のです ―― これが、権力です。

Senior is stronger, because of their life time. This is power.

-----

私は、若いころに、様々なアイデアや理想を、年上の人に叩き潰されてきました。

When I was youth, several ideas and ideals of mine had been broken by seniors.

年上の人のロジックは、常に完璧でした。ですので、私は常に挫折を続けてきました。

Their logics were always perfect, and I had to continue to lose.

それ故、私が、「人の言うことを聞かない能力」という観念に到達するまでには、随分時間がかかったものです。

Therefore, it took me a long time to arrive at the cencept of "the ability not to listen to others".

柔軟で、頭が良く、コミュニケーションが高い若者、いわゆる「有能な若者」は、簡単に『老害』の餌食にされる傾向が強いです。

Flexible, smart, and communicative young people, the so-called "competent young people", tend to be easily preyed upon by the "old".

私は、『潰される側』と『潰す側』の両方で、この事実を知っています。

I know this reality from the side of 'crushed side' and the 'crusher side'.

-----

ですから、今の私に必要なものは、

So, I think that what I have to have is

『知っていることを、沈黙し続ける能力』

'The ability to remain silent about what I know.'

です。

そして、その能力を最大限発揮する最も簡単なアプローチは『議論をしない』ということです。

And the easiest approach to maximize that ability is to 'not argue'.

今の私には、『"お互いに分かり合わない"努力』が求められていると、実感しています。

I realize that I am now required to make an effort to "not understand each other.

2022/09,江端さんの技術メモ

(Step.1) vscodeでmarkdownを使って本文を書いて、PDF(A4サイズ)にする

vscodeに以下の拡張機能は絶対に入れる

Visual Studio CodeのMarkdown編集から、いきなりPDFを作ったり、目次を追加したりできる件

vscodeでMarkdownを使って文章を書いている時、図面のコピペを文書の中にサクっと入れることができるアドイン "Paste Image"

(Step.1) SAIやPowerPointを使って、表紙と裏表紙を描いて、PDF(A4サイズ)にする

(Step.3) ConcatPDF(GUI)を使って、上記をマージして、書籍の名前のファイル名に保存する

(Step.4) 「江端さんの本屋さん」へアップロードする

新しいファイルをドラッグして、完了

ちなみに、以前のバージョンを購入して頂いた方は、最新版を無料で御提供する旨を、メッセージに追加(現在は、『メールでご連絡下さい』としているが、自動的にやる方法があるのか? 現在調査中)。

 

2022/09,江端さんの忘備録

昨日、以前自分で作ったはずの、Go言語のFuzzy推論ライブラリを探していました。

Yesterday, I was searched "fuzzy reasoning library with Golang" that I had made before.

ついでに、Go, Fuzzyでサーチエンジンをかけたのですが、"Go"、"Fuzzing"というWordで大量ヒットして、驚いています。

In addition, I ran a search engine, and I was surprised to find a large number of hits on the word "Go", "Fuzzing".

―― ここに至って、まさかのファジィ推論の復権? それもGolangで?

"Returning to 'Fuzzy Reasoning' ? with Golang? Now?"

と、思ったのですが、全く違う話でした。

I was foolish to think even for a moment.

-----

GolangのFuzzing機能とは、『プログラムの機能が想定していない入力を与える事でバグを発見するアプローチ』で、「プログラムのバグ発見用テストツール」ということのようです。

Golang's Fuzzing function is "an approach to finding bugs by providing input that is not expected by the program's functionality," and it is a "testing tool for finding bugs in programs.

fuzz: 警察(名詞)

fuzz: police (noun)

fuzzy: あいまいな(形容詞)

fuzzy: ambiguous (adjective)

名詞と形容詞で、これほど意味の変ってくる単語も珍しいなぁ、と思っています。

I think it is rare to change the meanings of word just between noun and adjective like this.

2022/09,江端さんの忘備録

私の未来予想は、これまで、ダイナミックに外れてきました。

My future predictions has been out of mark dynamically.

ですので、皆さんは、私の言うことは、あまり信じない方がいい、と、かなり本心から思っています。

So I am sorry that you don't have to believe what Ebata says no much from the bottom of my heart,

と逃げをうった上で申し上げますが、

And I'm going to say this with an evasive answer.

―― ロボットによる介護は、(少なくとも、私のフェーズでは)ダメなんじゃないかな

"I think robotic caregiving is a no-go (at least in my phase)"

と、思うのです。

もっとも、これは「完全人型ロボット」という意味で、パワードスーツの方向は希望はあると思っていますが。

However it is the case of "full humanoid robot", on the other hand, I think that "powered suite" has a little hopes.

-----

最近、私がショックを受けたパラダイムは、『マッチョ介護』です。

The paradigm that has shocked me recently is 'macho caregiving'.

『ITや制御やロボットがナンボのもんだ。これが正解だ』

"IT, control, and robot are meaningless. The 'macho caregiving' is right answer".

と、頭をぶん殴られるほどの衝撃を受けました。

I was so shocked that I was hit over the head.

父と母が亡くなり、今後の介護フェーズは、私たち夫婦の問題に移行します。

Through the death of my father and mother, the caregiving phase is going to move to my wife and me.

その準備としては、お金や設備などもありますが、介護をする側になることを考えれば「マッチョ」は分かりやすく、おそらくはかなりコストパフォーマンスなアプローチです。

For the preparation, we will need money and devices, however, for the side of the caring , "macho" is easy to understand and a cheaper strategy.

被介護者になるリスクを減らすという観点でも、良いアプローチと思います。

From the viewpoint of risk management to avoid being a care receiver, this is a good approach.

-----

こういう考え方が出て来たのは、これを作ってからです。

This paradigm has come to me, since I made the following device.

部屋に鉄棒を作ってみた

今の私は、(ずるい方法の)懸垂20回、ぶらさがり時間は60秒を軽く越えることができます。

Now I can do 20 sneaky pull-ups and keep my body hanging over 60 seconds.

さらに、最近は、他のメニューも加えて、全身運動に工夫をするようにしています。

These days, I have added new menus for full body exercise.

―― まだ間に合うかもしれない

"It might be not too late"

と思い、現在は、筋トレ専用のスポーツジムなどの巡回ツアーを開催しています。

So, I am organizing a tour of gyms and other facilities for muscle training.

-----

ただ、月額費用、2万円/月は、ちょっと高いんですよね。

However, \20K yen/month is too expensive for me.

普通のフィットネスセンターは、人数が多いし、市民運動センターは遠い。

Ordinal fitness club has many members, and the civic exercise center is far from my house.

モチベーションも「介護」一択です。

My motivation of muscle training is just for "caregiving".

マッチョな体になって、女性にモテたい、という心理は、私の人生で、1ナノ秒も登場したことがありません。

I have never wanted to have a macho body and be popular with the woman at all in my life.

(そもそも、私は、"マッチョ = バカ"という、酷い偏見を持っていた人間でした。今は、"尊敬"、"有用"にパラダイムシフトしています)

(To begin with, I thought "Macho is stupid" that is terrible prejudice. Now I change my mind to "respect" or "useful")

加えて、私は「"引きこもり"大好き人間」です。

In addition, I am a "recluse lover".

-----

先ずは、人間を運搬できるだけの筋力と、ぎっくり腰対策ができる程度のトレーニングを、『自宅』でできないものか模索しています。

So, I am searching how to get muscle to move a person, and avoid "strained back" just in my house.

上記の鉄棒のように、自宅を加工するのはことはO.K.で、工作は大好きなので、その方向から、皆さんのアドバイスを頂けると、大変助かります。

Like the the above "iron bar", I love DIY making or modifying my house, so I appreciate if you give me some advices.

よろしくお願い致します。

Thank you for your help in advance.

2022/09,江端さんの技術メモ

最近、スペルチェックをvscodeにやらせていて、emacsでのリロードを何度もやっているのだけど、これが中々に面倒で、これを一発でできないものか、色々調べた結果です。

方針: 面倒なので、".emacs" だけの記載で終了したい
操作:<F5>押すだけ
判ったこと: ".emacs"の最後に追記すると動かない(私の環境だけかもしれないが) → ".emacs"の真ん中あたりに突っ込んだ。

;;;; バッファを一発でリロードする (.emacsの最後に記載したら動かなかったので、真ん中くらいに移動)

(defun revert-buffer-no-confirm (&optional force-reverting)
  (interactive "P")
  ;;(message "force-reverting value is %s" force-reverting)
  (if (or force-reverting (not (buffer-modified-p)))
      (revert-buffer :ignore-auto :noconfirm)
    (error "The buffer has been modified")))

;; reload buffer
(global-set-key (kbd "<f5>") 'revert-buffer-no-confirm)
;;(global-set-key "\C-c\C-r" 'revert-buffer-no-confirm)
;;(global-set-key "\M-r" 'revert-buffer-no-confirm)
;(global-set-key "\C-c\C-m" 'revert-buffer-no-confirm)

2022/09,江端さんの技術メモ

こっちはPythonで書いたファジィ(Fuzzy)推論コードです。



# -*- coding: utf-8 -*-
# 上記の一行がないと、コメント分の和文も全部エラーになる 

# シンプルファジィ推論プログラム ver0.0 2015年12月15日
# シンプルファジィ推論プログラム ver0.1 2023年04月20日 print文の仕様変更対応

# メンバーシップ関数は、前件部、後件部ともに3つに固定した単純なもの
# 推論方式は、単純なmin-max重心法のみ



class condition_MF:
    
    center = 0
    width =  100
    PV ="LESS"

    def __init__(self, center, width, PV):
        self.center = center
        self.width = width
        self.PV = PV

    # x,yは、メンバーシップ関数上の座標を示す
    def func(self, x):
        if (self.PV == "LESS"):
            if (x <= self.center - self.width):
                y = 1.0
            elif (x <= self.center):
                y = - 1.0 / self.width * (x - self.center)
            else:
                y = 0.0        
        elif (self.PV == "ZERO"):
            if (x <= self.center - self.width):
                y = 0.0
            elif (x <= self.center):
                y = 1.0 / self.width * (x - self.center) + 1.0
            elif (x <= self.center + self.width):
                y = -1.0 / self.width * (x - self.center) + 1.0
            else:
                y = 0.0       
        elif (self.PV == "MORE"):
            if (x <= self.center):
                y = 0.0
            elif (x <= self.center + self.width):
                y = 1.0 / self.width * (x - self.center)
            else:
                y = 1.0
        
        return y

class action_MF:
    center = 0 # 値はダミー
    width =  100 # 値はダミー
    PV ="ZERO" # 値はダミー
    y = 0.0 # 最大値で更新されていく
    x = 0.0 # 値はダミー

    def __init__(self, center, width, PV):
        self.center = center
        self.width = width
        self.PV = PV

        if (self.PV == "LESS"):
            self.x = self.center - self.width
        elif (self.PV == "ZERO"):
            self.x = self.center
        elif (self.PV == "MORE"):
            self.x = self.center + self.width
        else:
            print ("error")

    # yを最大値で更新していく
    def func_Max(self,b):
        self.y = max(b, self.y)

    # X座標を返す
    def func_X(self):
        return self.x

    # (最大値で更新された、最後の)Y座標を返す
    def func_Y(self):
        return self.y

temp_High = condition_MF(20.0, 10.0, "MORE") # 温度が高い
temp_Middle = condition_MF(20.0, 10.0, "ZERO") #温度が普通
temp_Low = condition_MF(20.0, 10.0, "LESS")# 温度が低い

humi_High = condition_MF(50.0, 20.0, "MORE") # 湿度が高い
humi_Middle = condition_MF(50.0, 20.0, "ZERO") #湿度が普通
humi_Low = condition_MF(50.0, 20.0, "LESS")# 湿度が低い

switch_High = action_MF(0.0, 1.0, "MORE") # エアコンの温度設定を上げる("+1"にする)
switch_Middle = action_MF(0.0, 1.0, "ZERO")# エアコンの温度設定に何もしない("0"にする)
switch_Low = action_MF(0.0, 1.0, "LESS") # エアコンの温度設定を下げる("-1"にする)


# 入力値(温度27度、湿度57%)
t = 35.0
h = 80.0

# (1)「もし、温度が高くて、湿度が高ければ、エアコンの温度設定を下げる」
a1 = min(temp_High.func(t),humi_High.func(h))
print (a1)
switch_Low.func_Max(a1) 

print ("Low") 
print (switch_Low.func_Y()) 

# (2)「もし、温度が普通で、湿度が高ければ、何もしない」
a2 = min(temp_Middle.func(t),humi_High.func(h))
switch_Middle.func_Max(a2) 

print ("Middle") 
print (switch_Middle.func_Y()) 

# (3)「もし、温度が高くて、湿度が普通なら、エアコンの温度設定を下げる」

a3 = min(temp_High.func(t),humi_Middle.func(h))
switch_Low.func_Max(a3) 
print ("Low") 
print (switch_Low.func_Y()) 

# (4)「もし、温度が低くて、湿度が低ければ、エアコンの温度設定を上げる」
a4 = min(temp_Middle.func(t),humi_Low.func(h))
switch_High.func_Max(a4) 
print ("High") 
print (switch_High.func_Y()) 

# (5)(追加)もし温度が普通で、湿度が普通なら、何もしない
a5 = min(temp_Middle.func(t),humi_Middle.func(h))
switch_Middle.func_Max(a5) 
print ("Middle") 
print (switch_Middle.func_Y()) 

# 重心値を求める
# (ルールが推論空間を網羅していないと、ゼロ割が発生することがあるので注意)

reasoning =  (switch_High.func_X() * switch_High.func_Y()  + switch_Middle.func_X() * 
switch_Middle.func_Y()  + switch_Low.func_X() * switch_Low.func_Y()) / (switch_High.func_Y()  + switch_Middle.func_Y()  + switch_Low.func_Y())

print ("\n reasoning")
print (reasoning)

元ネタはこちら(クリックするとページに飛びます)。

ファジィ推論

2022/09,江端さんの技術メモ

Go言語を使った自作のファジィ(Fuzzy)推論コードを探していたのですが、見つけることができずにちょっとショックを受けております。

というか、Go言語どころか、C言語でも見つけられなかった(いや、あるはずだ)ので、今、PCの中探して見つかったものをアップしておきます。

毎回スクラッチから作るのも迂遠なので。

↓のコードですが、こちらのコラムで使ったものだと思います。

/*
  このプログラムをfuzzy.cpp"という名前で保存して、
  gcc -g fuzzy.cpp -o fuzzy
  でコンパイルして下さい。
*/



#include <stdio.h>
#include <stdlib.h>


// 共通関数
double max(double a){
    return a;
}

double max(double a, double b){
    if (a > b) 
        return a;
    else 
        return b;
};

double max(double a, double b, double c ){
    return max(max(a,b), max(b,c)); 
};

double max(double a, double b, double c, double d ){
    return max(max(a,b,c), d); 
};

double min(double a){
    return a;
}

double min(double a, double b){
    if (b > a) 
        return a;
    else 
        return b;
};

double min(double a, double b, double c ){
    return min(min(a,b), min(b,c)); 
};

double min(double a, double b, double c, double d ){
    return min(min(a,b,c), d); 
};


// ファジィ表現
typedef enum scale {LESSLESS, LESS, ZERO, MORE, MOREMORE} SCALE;

// 前件部メンバーシップ関数(山3つ)クラス
class condition_MF3
{
private:
    double center;
    double width;
    SCALE express;
   
public:
    condition_MF3(double _center, double _witdth, SCALE _express){
        center = _center;
        width = _witdth;
        express = _express;

        // 使用できないファジィ表現を使った場合は止める        
        if ((express == LESSLESS) || (express == MOREMORE)){
            printf("wrong expression used \n");
            exit(0);
        }

    };
    double func(double _x);
};

double condition_MF3::func(double _x)
{
// x,yは、メンバーシップ関数上の座標を示す
    double x = _x;
    double y = 0.0; // yの値は、必ず0以上1以下になる

    if (express == LESS){
        if (x <= center - width){
            y = 1.0;
        }
        else if (x <= center){
            y = - 1.0 / width * (x - center);
        }
        else{
            y = 0.0;
        }
    }
    else if (express == ZERO){
        if (x <= center - width){
            y = 0.0;
        }
        else if (x <= center){
            y = 1.0 / width * (x - center) + 1.0;
        }
        else if (x <= center + width){
            y = -1.0 / width * (x - center) + 1.0;
        }
        else{
            y = 0.0;
        }
    }
    else if (express == MORE){
        if (x <= center){
            y = 0.0;
        }
        else if (x <= center + width){
            y = 1.0 / width * (x - center);
        }
        else{
            y = 1.0;
        }
    }
    else {
        printf("wrong expression\n");
        exit(1);
    }

    return y;
};

// 前件部メンバーシップ関数(山5つ)クラス
class condition_MF5
{
private:
    double center;
    double width;
    SCALE express;
   
public:
    condition_MF5(double _center, double _witdth, SCALE _express){
        center = _center;
        width = _witdth;
        express = _express;
    };
    double func(double _x);
};


double condition_MF5::func(double _x)
{
// x,yは、メンバーシップ関数上の座標を示す
    double x = _x;
    double y = 0.0; // yの値は、必ず0以上1以下になる

    if (express == LESSLESS){
        if (x <= center - 2.0 * width){
            y = 1.0;
        }
        else if (x <= center - width){
            y = - 1.0 / width * (x - (center - 2.0 * width)) + 1.0;
        }
        else{
            y = 0.0;
        }
    }
    else if (express == LESS){
        if (x <= center - 2.0 * width){
            y = 0.0;
        }
        else if (x <= center - width){
            y = 1.0 / width * (x - (center - width)) + 1.0;
        }
        else if (x <= center){
            y = -1.0 / width * (x - (center - width)) + 1.0; 
        }
        else{
            y = 0.0;
        }
    }
    else if (express == ZERO){
        if (x <= center - width){
            y = 0.0;
        }
        else if (x <= center){
            y = 1.0 / width * (x - center) + 1.0;
        }
        else if (x <= center + width){
            y = -1.0 / width * (x - center) + 1.0;
        }
        else{
            y = 0.0;
        }
    }
    else if (express == MORE){
        if (x <= center){
            y = 0.0;
        }
        else if (x <= center + width){
            y = 1.0 / width * (x - (center + width)) + 1.0;
        }
        else if (x <= center + 2.0 * width){
            y = -1.0 / width * (x - (center + width)) + 1.0; 
        }
        else{
            y = 0.0;
        }
    }
    else if (express == MOREMORE){
        if (x <= center + width){
            y = 0.0;
        }
        else if (x <= center + 2.0 * width){
            y = 1.0 / width * (x - (center + 2.0 * width)) + 1.0;
        }
        else{
            y = 1.0;
        }
    }

    return y;
};

// 後件部メンバーシップ関数(山3つ)クラス  
class action_MF3
{
private:
    double center;
    double width;
    SCALE express;

    double x;
    double y;

public:
    action_MF3(double _center, double _witdth, SCALE _express){

        y = 0.0; // yの値は、必ず0以上1以下になる
       
        center = _center;
        width = _witdth;
        express = _express;
        
        if (express == LESS){
            x = center - width;
        }
        else if (express == ZERO){
            x = center;
        }
        else if (express == MORE){
            x = center + width;
        }
        else{
            printf("wrong scale expression\n");
            exit(0);
        }
    };
    
    void func_Max(double b){
        y = max(b, y);
    };
    
// X座標を返す
    double func_X(void){
        return x;
    };
    
    // (最大値で更新された、最後の)Y座標を返す
    double func_Y(){
        return y;
    };

};

// 後件部メンバーシップ関数(山5つ)クラス  
class action_MF5
{
private:
    double center;
    double width;
    SCALE express;

    double x;
    double y;

public:
    action_MF5(double _center, double _witdth, SCALE _express){
        y = 0.0; // yの値は、必ず0以上1以下になる
       
        center = _center;
        width = _witdth;
        express = _express;
        
        if (express == LESSLESS){
            x = center - 2.0 * width;
        }
        else if (express == LESS){
            x = center - width;
        }
        else if (express == ZERO){
            x = center;
        }
        else if (express == MORE){
            x = center + width;
        }
        else if (express == MOREMORE){
            x = center + 2.0 * width;
        }
        else{
            printf("wrong scale expression\n");
        }
    };
    
    void func_Max(double b){
        y = max(b, y);
    };
    
// X座標を返す
    double func_X(void){
        return x;
    };
    
    // (最大値で更新された、最後の)Y座標を返す
    double func_Y(){
        return y;
    };

};

int main()
{
    // ダイエット経過期間
    condition_MF3 Period_Short(14, 14, LESS); // 0日
    condition_MF3 Period_Middle(14, 14, ZERO); // 14日
    condition_MF3 Period_Long(14, 14, MORE); // 28日

    // いわゆる「停滞期」(14日間あたりの平均減重変化量)
    condition_MF3 WeighChange_Small(1.0, 1.0, LESS); // 0kg
    condition_MF3 WeighChange_Middle(1.0, 1.0, ZERO); // 1kg
    condition_MF3 WeighChange_High(1.0, 1.0, MORE); // 2kg

    // 苦痛度
    condition_MF3 Suffer_Zerol(400.0, 400.0, LESS); // 0
    condition_MF3 Suffer_Middle(400.0, 400.0, ZERO); // 400
    condition_MF3 Suffer_Hight(400.0, 400.0, MORE); // 800

    // BMI
    condition_MF5 BMI_lowlow(22.0, 3.0, LESSLESS); // 痩せすぎ(15.0)
    condition_MF5 BMI_low(22.0, 3.0, LESS);// 痩せぎみ(19.0)
    condition_MF5 BMI_Normal(22.0, 3.0, ZERO);// 普通(22.0)
    condition_MF5 BMI_High(22.0, 3.0, MORE); // 太りぎみ(25.0)
    condition_MF5 BMI_HighHigh(22.0, 3.0, MOREMORE);// 太りすぎ(28.0)

    // 一日の摂取カロリー
    action_MF5 Eat_LittleLittle(2500, 1000, LESSLESS); // 500 Kcal
    action_MF5 Eat_Little(2500, 1000, LESS);// 1500 Kcal
    action_MF5 Eat_Normal(2500, 1000, ZERO);// 2500 Kcal
    action_MF5 Eat_Lot(2500, 1000, MORE);// 3500 Kcal
    action_MF5 Eat_LotLot(2500, 1000, MOREMORE);// 4500 Kcal



    
    
    // 超シンプルシミュレータ投入
    // 体重変動シミュレーションプログラム
    //基礎代謝量と求め方	?ハリス・ベネディクト方程式(日本人版) 計算式
    //http://www.kintore.info/kisotaisya_mass/index.cgi
    //【計算式】
    // 男性 66.5+(体重kg×13.8)+(身長cm×5.0)-(年齢×6.8)
    // 女性 665.1+(体重kg×9.6)+(身長cm×1.9)-(年齢×7.0)							
    // 江端智一 2014日2月4日現在のデータを使って計算
    double weight = 78.0;  // 開始時の体重 78.0kg
    double lengthw = 172.0;  // 身長 172cm
    double age = 49.0 + 94/365;  // 開始時の年齢 49歳と94日 (2014年2月4日現在)

    // 最初の基礎代謝カロリー 男性  66.5+(体重kg×13.8)+(身長cm×5.0)-(年齢×6.8)
    double consumption_calorie =  
        66.5 + weight * 13.8 + 172.0 * 5.0 - age * 6.8;
    // このカロリーに運動消費カロリーを加えて、
    // トータルの一日の消費カロリーを算出する

    // (現在の体重 66.5kgにおいて)一日運動消費カロリー 708kcalと推定し、
    // このカロリーは、体重に比例するものと仮定する。
    consumption_calorie += weight/66.5 * 708.0;
    printf("consumption_calorie = %f\n",  consumption_calorie);

    double last_weight[14]; // 過去14日分の体重
    
    // 最初は全部同じ体重とする 14日経過までは同じ体重とする
    for (int i = 0; i++; i < 14){
        last_weight[i] = weight;
    }

    // ここからループ開始
    for (int day=0; day < 1460; day++){ // 1460日は、ちょうど4年分の日数
        // 7kcal = 1g = 0.001kg とする    

        // 体重データを一日分ずらす
        for (int i = 0; i++; i < 14-1 ){
            last_weight[i+1] = last_weight[i];
        }
        last_weight[0] = weight;
        
        // 線形補完の傾きだけを求める(14日分)
        // http://d.hatena.ne.jp/rainlib/20090112/1231735459
        double k1=0,k2=0,k3=0,k4=0;
        for (int i = 0; i++; i < 14 ){
            k1 += (double)i * (double)i;
            k2 += (double)i * last_weight[i];
            k3 += (double)i;
            k4 += last_weight[i] *last_weight[i];
        }
        double dW = (14.0 * k2 - k3 * k4) / (14.0 * k4 - k3*k3); // 14

        // BMIの計算式 体重(Kg)÷身長(m)÷身長(m) 江端の身長172cm
        double bmi = weight / 1.72 / 1.72;
        
        // [ルール1] ダイエット開始直後は、「無条件にがんばれる」
        double r1 = min(Period_Short.func(day));
        Eat_Little.func_Max(r1);
        //printf("r1: %f\n",r1);
        
        //printf("Eat_Little.func_X() = %f\n",Eat_Little.func_X());
        //printf("Eat_Little.func_Y() = %f\n",Eat_Little.func_Y());
        
        // [ルール2] ダイエット一ヶ月を過ぎても、停滞し続けると「切れる」
        double r2 = min(Period_Long.func(day),WeighChange_Small.func(dW));
        Eat_LotLot.func_Max(r2);
        //printf("r2: %f\n",r2);
        
        // [ルール3] ダイエット2週間を過ぎて、停滞し続けると「緩んでくる」
        double r3 = min(Period_Middle.func(day),WeighChange_Small.func(dW));
        Eat_Normal.func_Max(r3);
        //printf("r3: %f\n",r3);
        
        // [ルール4] 停滞期がなく順調に体重が落ちている場合は「がんばれる」
        double r4 = min(WeighChange_High.func(dW));
        Eat_Little.func_Max(r4);
		//        printf("r4: %f\n",r4);
        
        // [ルール5] ダイエット一ヶ月を過ぎて、再び太り出してくると、またダイエットを再開してしまう
        double r5 = min(Period_Long.func(day),BMI_High.func(bmi));
        Eat_Little.func_Max(r5);
        //printf("r5: %f\n",r5);
        
        // [ルール6] ダイエット一ヶ月を過ぎて、太り過ぎると、滅茶苦茶なダイエットを始めてしまう
        double r6 = min(Period_Long.func(day),BMI_HighHigh.func(bmi));
        Eat_LittleLittle.func_Max(r6);

        //printf("r6: %f\n",r6);
		/*        
        printf("Eat_LittleLittle.func_X() = %f\n",Eat_LittleLittle.func_X());
        printf("Eat_LittleLittle.func_Y() = %f\n",Eat_LittleLittle.func_Y());
        printf("Eat_Little.func_X() = %f\n",Eat_Little.func_X());
        printf("Eat_Little.func_Y() = %f\n",Eat_Little.func_Y());
        printf("Eat_Normal.func_X() = %f\n",Eat_Normal.func_X());
        printf("Eat_Normal.func_Y() = %f\n",Eat_Normal.func_Y());
        printf("Eat_Lot.func_X() = %f\n",Eat_Lot.func_X());
        printf("Eat_Lot.func_Y() = %f\n",Eat_Lot.func_Y());
        printf("Eat_LotLot.func_X() = %f\n",Eat_LotLot.func_X());
        printf("Eat_LotLot.func_Y() = %f\n",Eat_LotLot.func_Y());
        */
        
        double source_calorie =  
            (Eat_LittleLittle.func_X() * Eat_LittleLittle.func_Y() + 
             Eat_Little.func_X() * Eat_Little.func_Y() +
             Eat_Normal.func_X() * Eat_Normal.func_Y() +
             Eat_Lot.func_X() * Eat_Lot.func_Y() +
             Eat_LotLot.func_X() * Eat_LotLot.func_Y() )  
            /
            (Eat_LittleLittle.func_Y() + 
             Eat_Little.func_Y() +
             Eat_Normal.func_Y() +
             Eat_Lot.func_Y() +
             Eat_LotLot.func_Y() ) ;
        
        printf("\n source_calorie = %f\n",source_calorie);

        double diff_weight = (source_calorie - consumption_calorie)/7.0 / 1000.0;
        weight += diff_weight;
        age += 1.0/365.0;
        consumption_calorie =  66.5 + weight * 13.8 + 172.0 * 5.0 - age * 6.8;
        consumption_calorie += weight/66.5 * 708.0;
        //       printf("day:%d\tweight = %f\tconsumption_calorie =%f\n", day,weight, consumption_calorie);
    }



}

ファジィ推論