Saturday, May 28, 2016

Open CV installation to MAC OSX by homebrew

I installed OpenCV to MAC OSX by using homebrew one month ago, then I had a worrisome thing which I found many people also had, so I like to share my case because this depends 
on people's environment.
There are a lot of web pages about how to install OpenCV by homebrew to MAC OSX, so I omit it here.

During the installation, it looks like stuck at 
==> make bootstrap
in the middle. And the name of a tab in terminal changes sometimes rapidly but stops sometimes. What is concern is that it does not finish and looks stuck. As far as I found in web search, this takes long time actually. It took about one hour in my case to be finished. 

MAC spec is 
OSX Version 10.9.5
2.5 GHz Intel Core i5
4 GB 1600 MHz DDR3
I hope this helps somebody.

Sunday, May 22, 2016

Find prime numbers by script

It's been more than one year since I posted last time. Actually, I was busy with my job. 
I'm not a programmer, but I often write a script to extract specific data from numerical simulation results and to make some input sequence files for simulation. When it comes to this type of work, Perl seems to be better than others according to web evaluation. 
One day, I heard news that the longest prime number was found by the computer, and I became wondering how long does it take to find prime numbers by a Perl script. 

 Here is a script to find numerical numbers up to N.

# script to find prime numbers to N
$N=100000;
# 2 is an exceptional number to this script
print "2\n";
$numP=1;
# start to find prime numbers from 3
for($k=3;$k<=$N;$k+=2){
        $m=2;
        until($k%$m==0){
        $m++;
        }
        if($k==$m){
        print "$k\n";
        $numP++;
        }
}
print "\n";
print "the number of prime number to $N is $numP\n";

In this script, I take the number 2 as an exceptional one, and try to find prime numbers from 3 in for-loop. For each $k over 3, modulo is performed from 2 to $k until 0 is found. if $k is dividable by itself, then it is a prime number. To save time, even numbers are skipped.

I compared the process time of three computers by using build-in function "time" in Linux.
time perl scriptname.pl
As is set above script, I run the script to find numbers up to 100,000. Here are comparison results.
 8 minutes -- Raspberry Pi 2 model B 
36 seconds -- Mac book pro 2012
17 seconds -- Company Linux machine
This makes sense to me in terms of computer spec. Company machine is as powerful as being able to run the advanced spice simulator easily and memory is also over 100G.

When $N increases, then the process time also increases exponentially. Try it.

I'm now thinking to write a script to calculate pi next.

Sunday, February 1, 2015

The art of happiness ; My memo





I would like to put memos about a book, The art of Happiness.


I was in a depress situation last August. That's because I had suffered from a pain, not chronic around the left stomach on my back for a few weeks and I thought I might be suffering from some serious disease. And I had a clue about that. I had drunken alcohol more than I might be able to handle with my body, due to chronic stress for a few months. The pain disappeared two weeks later and nothing was found out by medical check, so now I'm fine. During that time, I was thinking why only I was treated badly and how unhappy I was by looking at my situation in my job and was suffering the pain. So I was looking for something to make me feel calm down to look forward the future positively, and come across a book, "The art of happiness". I have heard of Dalai Lama, but I had not read articles, videos, let alone books. As for myself, I'm not a Buddhist and don't have any religious beliefs actually, although my American friend who turned  a Buddist always tells me that Japanese people don't say they have any beliefs, but their behavior is exactly following what Buddhism teaches. Yes, that's true actually, because people used to be religious long time years back. Growing up in Japan merely leads us to behave like that, naturally regardless of nationalities. So even Americans who moved to Japan in their early ages behave like than unconsciously. The book seems to be very famous, so it's available in English in a bookstore in Tokyo. I usually order books in English by Amason because books in English are not still popular,and available books in bookstores are limited unfortunately. 

I had finished reading the book soon after the purchase, and there are a lot of comments and sentences which I like to remember for the rest of my life, so I underlined them in red in the book. What is the most valuable thing was that I could be calm down and I have been able to gradually change my way of thinking by incorporating what I learned throughout reading the book. 

So here is my memo.



Compassion for others increase own happiness. And they are a two-way street.
Cultivating happiness benefits not only oneself, but also family community. Furthermore happiness is contagious. Seeking happiness is basic human life.
Generally happy people are more social, flexible and tolerate life's frustration than unhappy people.
 Comparison causes breed envy and frustration, which causes less satisfaction and less happiness. This can be changes by how to perceive own situation and how to deal with it. One's mind state determines how happy we are, and external events never directly do that. Even those who are struck by serious disease can bring back their mind back to normal after a while.
Excessive desire leads to greed. Nobody is born with greedy mind. Nobody is programmed genetically to make wars. They are acquired later, so improvement is possible later as well.
Greed makes more greed. You never are going to be satisfied even though you get something you wanted. 
Strong sense of contentment is a strong antidote of greedness.
How we can acquire contentment is to appreciate what we have. Gratification of what we have.
One of ways to seek happiness is to learn how positive thinking, emotion, and behavior are good forms and how negative thinking and antidote are harmful for us. After figuring it out, it's important to develop your positive attitude.
 Causality is a basic law in Buddhism, so let's find out what bring you happiness.
 Negative things include hatred, jealousy and anger.
When you get up, it's better to think about how you utilize the day and how not to waste the day. When you go to bed, it's important to reflect your day and consider what you should have done and what you regret today. Repeating this every day gives you positive attitude, which makes you feel happy. This is not a habit which does not happen overnight. It takes time.
Scientists call our brain plasticity because that's configurable if we want even though its time depends on people.
If we want to deepen relationship with others, it's important to get to know the deeper nature of others and relate to him/her on that level, instead of merely on superficial characteristics. Developing compassion and altruism (<--> egoism) has a positive impact on physical and emotional health.
Suffering is usually negative and people react it negatively, which make people unhappy. So it's important for you to understand how you react it when it arises. Accepting that suffering is a basic part of our life is one of the steps to do that. The developing perception of that is important. Ignorance is not referring to the lack of information, but to the fundamental miperceptison of the nature of life and all phenomena.
When you go to a restaurant for dinner, what would you feel if the service is as slow as you can't endure ? It's normal to feel that  the service is really bad and you never come again, and annoyance arises finally. However, what would you feel if a water come to you at the end of the dinner and appologize for slow service because one of waiters had a death in a family and one of cooks called in sick just last minute. How would you react to it after you hear that ?
Whenever there is intense emotion, there tends to be a disparity between how things happen and how things really are.
Finding own contribution to anger and frustration is important.
Regardless of whether we are successful or not, the honest attempt to figure out own contribution to a problem allows a certain shift of forces that helps to break through a narrow pattern of thinking that leads to the destructive feeling of unfairness and that is the source of the discontentment in ourselves.
The ability of changing perspective is strong tool which enables you to deal with daily problems. However, it's possible to be able to cope with your problems immediately. Changing perspective does not happen overnight. It can be acquired through a process of learning, training and practice getting used to the new perspective.
Finding meaning in suffering is a great tool which enable you to deal with difficulty. And suffering is an opportunity to consider other's suffering. When you are aware of pain and suffering, it helps you develop your capacity of empathy, which allows you to relate to other's feeling. This also enhances your capacity for compassion toward others. There is no doubt that our attitude can affect the degree to which we suffer when we are in suffering.
The awareness of human impermanence is helpful, and its acceptance allows you to appreciate human existence, and it will give us the sense of urgency that we have to use the very precious moment.
If you encounter some obstacles in your life, it's definitely better to step back and tecontemp lathe longer term view rather than the shorter time view.
Posive state of mind can act as an antidote to a negative state of mind. The more you are used to behave positively, the more you are able to reduce the force of mental and emotional pain.
Repeatedly engagement in positive attitude brings about internal change of mind.
We can prepare to cope with anger and hatred with a positive attitude. Once it arises, you can analyze what causes and triggers anger in your internal mind, and you can think how to deal with it appropriately. Science also confirms that actively challenging, logically analyzing, and reappraising thought that trigger anger help dissipate
If you analyze situation, you will find out that the past is past. It's no use continuing to feel anger, which does not change the situation, rather causes continuous unhappiness.
Happy life is built on a foundation of a calm stable state of mind. The practice of inner discipline can include formal meditation techniques that are intended to help stabilize the mind and achieve that calm state. 

By reviewing these regularly, I will be able to recall the contents mentioned around these memos. It was the first time for me to read a book related to Buddhism, so there are a lot of important things which I found to be able to use in our daily life.

http://www.amazon.com/The-Happiness-10th-Anniversary-Edition-ebook/dp/B002UK6NO0

Wednesday, December 31, 2014

Memo of "How google works"

Here is my memo note about the book, "How google works", which I happened to find and finish to read last week. The book is written by Erick Schmidt and Jonathan Rosenberg, who have made Google as it is, together with founders, and the book is about the way of working and management of 21th century with smart creatives, which is what they have figured out to be necessary since they joined Google. In the Internet century, old style management does not work out because it worked for old type people who grew up without the Internet. There are a lot of sentences which I thought is important to remember. Therefore, I tried to list up them with some my interpretation.


  • Smart creatives have deep technical knowledge and plenty of hands-on experiences, and don't just design a concept, but build a prototype. Smart creatives are not afraid to fail because they think failure is usually something important which they can salvage.
  • The environment is also one of the important factors. Failure is not criticized, but appreciated for exploring possibilities.
  • Once you identify the people who have the big impact. then give them more to do. When you put more responsibilities on your best people, and trust them. They will keep doing well. The old quote is true, if you want something done, give it to busy people.
  • No is a tiny death to smart creatives. Saying yes begins things, and it is how things grow. Saying yes leads to new experiences, and the new experiences will lead you to knowledge and wisdom.
  • A venture capitalist will always follow the maximum of investment in the team, bot the plan because the plan is wrong. Since the plan is wrong, the people have to be right. Smart creatives spot flaws in the plan and adjust.
  • Henry Ford said that if he had listened to customers, then he would have gone out looking for faster horses.
  • Anyone who stops learning gets old, whether 20s or 80s. Anyone who keeps learning stays young. The greatest in life is to keep your mind young by learning.
  • If you think your ability is fixed, you'll set for yourself, what is called, performance goals, but if you have a growth mindset, you'll set for learning goals, which will drive you to take risks without worrying how you look like.
  • Being a good interviewer requires understanding the role, reading the resume, and the most important thing is to consider your question.
  • Supporting every opinion should come with data or empirical observation. Otherwise, it's not trusted at all.
  • A candidate's original resume should be kept as it is, so everyone can see the typos, and formatting errors. By doing this, interviewers can see what kind of reports can be expected from the candidate if he or she is hired.
  • If your people tell you that they are going to leave for starting own new business, then ask them for their elevator pitch, which is a venture capital word by asking "You have 30 seconds to impress me by your plan". What's the strategy ? Would you tell me if I were your investor ? If the answer is not good enough, then they are not ready to leave.
  • Prepare your own elevator pitch for your job. Let's say, you run into your CEO in the hallway, and he or she asks you what you are working on. What do you say ?
  • We don't seek to convince by saying "I think", but we seek to convince by saying '"Let me show". Visual reasoning usually works more effectively when relevant information is presented together.
  • Conversation is still the most important and valuable form of communication, but the technology makes it happen rarely.
  • For something to be innovative, it needs to be new surprising and radically usefull.
  • This is by Derek Sivers in TED talk. When creating a movement, attracting a follower is the most crucial step. The first follower is what transforms a loner nut into a leader.
  • Too many people are stuck in the old limited mindset. "They are not thinking big enough" is replaced by Larry Page to "Think 10x".
  • Coming up an idea is not good enough, building a prototype is necessary to attract people to follow.
  • I keep my attention on the question which I need to ask so that I can catch the issue of the future.
  • The question to ask is not what will be true, but what could be true. Asking what will be true entail making a prediction, but asking what could be true entail imagination.
  • Ask yourself what could happen in your industry in the next five years. What could change most quickly and what will not change at all.


Those are just memos for me to recall the contents of the book. There are a lot to things for me to remember for the 2015. Thinking about them does not make sense, and taking actions based on thouse is necessary actually.



Sunday, October 12, 2014

Swallowing Gastric camera (gastroscopy) first time

I would like to share my experience of an examination of gastric camera check which I took last month. I will be happy if I can help those who have not experienced this but need to take this and are afraid of taking this because it is generally believed to be painful. My case was very easy by using sedative which helped a lot actually. Let me tell you from the reason why I needed to take to process of the examination.

Why I needed to take the check

I felt something pain a little bit at the left side of my stomach and back in the middle of last August. This was not chronic, but the pain came sometimes once an hour and continued for a few minutes. As far as I can tell, the pain did not have any correlation with any actions like eating food or drinking water. I actually have felt similar symptom before, especially after drinking alcohol too much, and it was gone just one day. So I thought that the pain of this time was similar as before, because I had alcohol chronically for last a few months before that due to many events. However, I immediately stopped to drink alcohol just in case because it lasted a few days as was not expected, and tried to see if it improves. I felt great improvement soon and I thought that it worked out finally, but I concerned a little bit about that this time and I still continued to stop drinking for complete cure. However, the pain came again one week later after stop of the pain unfortunately, and I also felt strong pain as much as I could not stand it. So I decided to see a doctor in the following day before it became too late. What was lucky was that it was not chronic pain. I suspected that I might suffer from pancreatitis because of parts which hurt and the reason of drinking alcohol by checking symptom on the web. I was very afraid of that by thinking that I would never be able to drink again, and eating habit would be also limited. I saw a doctor in the following morning, and I took a blood test and x-ray check around my stomach. Precisely, those were only tests which could be done at the day because I saw a doctor without a reservation and a referral. The hospital which I visited was large, so test results became available in one hour fortunately. As it turned out, nothing wrong was found, as far as the doctor looked at results, and the doctor proposed a gastric camera check and ultrasound check in order to examine the cause of pain more precisely. I was stuck for a moment to consider whether I should take them or not because I had a prejudice that gastric camera check is painful, but I decide to make reservations for those tests just in case, while hoping that I could cancel them if the pain would be gone later. The hospital is large, so reservations were occupied until one month later, so my reservation became late September. Surprisingly, the pain was getting weaker gradually since that day, and it was gone completely after a few days later, so I once thought I was able to cancel reservations, but I changed my mind and again decided to take them just in case that I might develop initial diseases and could cure them thanks to early finding.

Procedures of the gastric camera test

Here were procedures in my case. My check time was morning at 9am, but I wondered if there is evening check time.

  1. Needed to finish dinner before 9pm one day before the check to clean stomach at the examination. Drinking water was allowed.
  2. One cup of water was allowed prior to 3 hours before the check. A little water was allowed only to wet my whistle.
  3. Drunk liquid drug before the check. I did not know what material this was, but a nurse told me that this was liquid for clear pictures.
  4. Took anesthesia sprayed around throat from mouth to avoid pain during the check as much as possible. This turned effective immediately, but the lasting time seems to be short because I felt so, and I asked the nurse if the anesthesia was enough once. She said that I don't have to worry about that, because I would have one more again later just before the check.
  5. I entered the examination room and laid down on a bed. It was just around 5 minutes later after the first the anesthesia. I got it again here as was explained. I asked sedative option for this test because it helped a lot, according to the instruction. I had sedative intravenously, and what was surprising was that I fell asleep soon after I got it. According to the nurse, most of people don't use this option. 
  6. When I was woke up after around 15 minutes later, the check was over. 
  7. I needed to take a rest for one hour on a bed in the hospital because I used sedative.
  8. I took one week for the doctor to look pictures again just in case.
What I felt honestly was that gastric camera check is easy if I can expect sedative, otherwise it's painful. That's because I remember slightly that I tried to move my body and and the nurse tried to hold my body during the check. I would imagine that it was painful unconsciously. 


The Result

I saw a doctor one week later. It seems that a doctor who examines result is different from a doctor who actually execute the check. I was a little bit nervous while considering the worst case scenario like a cancer or something serious disease, but it turned out that nothing wrong was found by gastric camera check and ultrasound. The doctor told me that stomach is very clean and there is also no problem by ultrasound, and I would not have to take further check because the pain disappear now. I was relieved to hear that and happy very much. My one month struggling was over at that time.

By looking back last one month

When I felt I needed to see a doctor, I inevitably thought about the worst case scenario like serious disease and concerned what was going to happen in that case and what I should do. For instance, I wondered whether or not I need to quit a job, and if I need to take care of diseases for the rest of my life while limiting food and drink, etc. Nothing was positive thinking actually at that time. I was really negative at that time, to be honest. I guess that this kind of thinking generally comes to mind for those who think that they might suffer from something serious diseases before check result does not come yet. I have done a lot of things for last one month and many things have changed. Most of them have something to do with mental and physical improvement things.


  • Consider what happiness is.
    At first, I wondered why I was suffering from this even thought I was still early 30s and why I was unfortunate actually. So I tried to find books about happiness and found "The art of happiness". The book is about happiness which Darai Rama tell and how to deal with unhappiness mentally. A European psychiatrist interviewed Darai Rama and tried to combine western and eastern idea about Happiness, then summarized it in the book. I am going to post the detail later in a different post, but the book changed my mind about happiness, and what is the most important is that it makes me think anything positive and consider others in different point of view with great idea of "compassion". My mental state was weak at that time, therefore it was so impressive and came to my mind deeply.
  • Walking and jogging
    Exercise was very good to make me feel good and made me feel I'm living. If I say so, many people would say that I was thinking too much and don't worry and I was not going to die. However, I felt that I might be going to die due to some diseases, so small happiness by doing walking was truly good for me.
The fact that I suffered from the unknown pain was not good actually, but it was good during the period that I was able to consider my life, learned happiness, change my thinking by Compassion and be able to go my life positively.

Sunday, July 13, 2014

Mental disease : He can start his new life from this month


I wrote this story to help someone help friends, colleagues and whoever could suffer from mental disease against your expectation as is often the case. This is the story about my colleague who I did not think suffered from mental disease, but who unfortunately did suffer for a few years. He is now recovering as much as he is able to start his new life with his new job.

He was one of my senior colleagues by 5 years older than me when I joined the company, and I started to work in a same development team. His way of talking was a little bit childish, and he graduated from a same university, and he is also a person who did not play the old soldier, so I did not feel that he was senior honestly and could get along with him. In addition to his personality, I respected his attitude and his seriousness toward his work. He seemed to be always right about what he did and what he said. He did not like ambiguity so he sometimes fought with someone over its ambiguity. I totally respected him regarding work.

Two years later, we worked together in one project whose schedule was very tight, and his role was to design circuits while discussing circuits' specification with a customer. As is always the case, but the customer frequently added, removed, and changed the specifications until the deadline. This happened for almost half a year, so he came early and left late after twelve. He was like walking dead, but he has a strong sense of responsibility so he finished his work finally. A few weeks later, we went for dinner and he told me that he was burned out due to the previous project and he could not sleep at night. However, I did not take it seriously because I felt that he did not seem to say so seriously. If I look back, he also did not take it seriously. A few months later, he told me that we saw a doctor because he could not sleep and took medication. Even he said so, I did not take it seriously because he talked about it openly to other peoples as well. This was a time when we should have taken an action to take care of him somehow by everybody who worked together with him, but we did not do that because there was nobody who had ever suffered from mental disease around us and we did not know how people suffer from it and did not know that anybody could be a victim depending on an environment these days.

A few months later, I was transferred to U.S office and we got separated, but sometimes exchanged emails to tell how we were doing. One year later, he came to the U.S office to attend a conference and we talked much and he confessed that we were still taking a few kinds of medicine for mental disease. However, he looked ok for me, although he was not actually. A few months later, I was told by a previous boss that he took a long sick leave and did not come to the office. I felt very sorry to hear that, but could not call him at that time because I was also suffering from mental disease a little bit. I did not have room to take care of others honestly.

When I came back to the Japan office one year later, he also recovered from the disease and was able to come to the office. He invited me for lunch and we talked about what was going on him so far. He said that he was almost like a wreck due to medicine when we was during sick leave. At first, he took one tablet of medicine per one time but there was a side effect of that, so he told his doctor it then his doctor increase one more different table to alleviate the side effect. And this repeated a few times and he took four kinds of tablet one time. It is obviously wrong to do this, but he did not doubt this because he suffered mentally. One day, he seemed to realize that something was wrong to increase medicine more, so he asked his doctor to reduce medicine. Since that time, he can gradually have reduced the number of tablets per one time. He is now taking only one table.

I got an email from him last month, and he was still in a long sick leave. He asked me to call him soon. I called him and asked him what was going on. He said that he got a new job and he was going to quit the current company and join a new company. That company is small, but he was appreciating that the company hired him even though he confessed that he still suffered from mental disease but gets better day by day. He seems to recover as much as he also be able to work again.

When I heard this, I was very happy as much as I could cry even over a phone. And I still feel responsible about his sick because I was not able to notice that. If I could had noticed that, there is a chance that he would not have had to suffer from it. 

I wish the all the best for his new endeavor.

Sunday, July 6, 2014

Make it stick : The science of successful learning

Here is my short summary of "Make it stick" which I finished last week. Authors firstly point out that what is generally believed is not a right way of learning and tell us how to learn efficiently based on experimental and statistical facts which many researchers have investigated so far. The way of learning presented in the book can be applied to any people from school children to elderly persons because learning is never ending process of our brain.



According to authors, mass practice makes sense in short term memory but not in long term memory. For example, many people might experience this in school test, and the established memory by mass practice is gone soon no matter how hard your work before tests. The book says that proper learning basically consists of retrieving, reflection, elaboration, and spaced learning in order to put what we learn into long term memory. Retrieving practice needs recalling idea, concepts or events from your memory regularly. Reflection and elaboration practice are processes that let you relate what you retrieve and what you have learned so far, and attach the new memory to the old memory. These additionally allow you to think what you should do next time better than it is now. For example, if you think that you fail to do presentation well, you need to reflect on what is wrong and consider improvement based on what you did and reflect it on next presentation. This is a point whether you are a good learner or not. Elaboration practice needs struggling process. For example, when you try to solve difficult math questions, you would struggle to solve them by retrieving what you know and relate what you retrieve to questions. The more you struggle, the more ways of solving remain longer in your memory finally, whether you can solve them by yourself or you look answers finally. The process of struggling is very important and it strengthens connections of neurons by synapse in your brain. Explaining what you learn in your words is also elaboration process. Spaced training is basically a repeated learning over many times. Repeating a few days would be better. Repeating a few hours does not make sense and is almost same with mass practice.
That's just small summary, but authors present a lot of experimental and statistical facts in the book to strengthen their claims. There are a lot of intriguing experimental facts, but here is one which is very interesting for me.
Intellectual ability is not fixed when you are born, but it depends on you to a large degree in your hand. There is a experiment that some students are praised for being able to solve problems (performance goal), but some students are praised for working hard for trying to solve problems (learning goal). What happened was that people with the performance goal unconsciously limit their goals by choosing solvable problems from next time because they are unconsciously afraid of failing to solve problems. On the other hand, people with the learning goal challenge even difficult problems because they are trained to be praised for working harder. With proper learning processes mentioned above, the latter group is likely to grow more than the former people.

Authours mention deliberate practice of 10,000 hours rule a little bit, but the right way of learning presented here is obviously related to it.
From my experience about my job, the right way of learning perfectly makes sense and it does in terms of 10,000 hours rule which is equivalent to 10 hours a day for three years. My MS degree is of theoretical physics, so the current job, circuit design, was pretty new for me when I joined the current company. Physics, of course, is fundamental to all science and it helps me a lot to understand new things soon. When I look back the past, the way of learning about the job fits the way of learning mentioned in the book. Every morning, I used to present and explain what I learned from a circuit design book to senior designers and get my misunderstanding corrected and get feedback. In the daytime, I apply what I learn to real circuit design and explain it to seniors and get feedback. I used to repeat this for a few years. In addition to these, I personally do study and reflect on what I did and consider how to improve it. This process obviously follows the processes mentioned in the book. Three years later, I could say that I could become an expert of this job because I did not need any help to proceed the my job and I could even teach something to others. This was also close to 10,000 hours. 

The point in the book is that there is the right way of learning and what is generally believed is not efficient. Additionally, it is pointed out that we can learn forever as long as we want to do that.