JAVA Program For A.I. Data Normalization
I needed to normalize my data for the sake of machine learning – i.e. training a neural network for automatic classification of unseen data. The formula I used for the normalization is ((value – minimum value)/(maximum value – minimum value)). I then rounded this to 2 decimal places.
In order to actually round off, I did another JAVA class specifically for this and used it in the main class.
This is not the most elegant programs you will ever come across but at least it does the job for me and I am sure it will do the job for someone else. The argument needs to be a text file containing numbers that need to be normalized. The other argument is the name of the text file that you want the output to be written. When you run it, it does the job quietly and doesn’t notify you of success. (It may notify you of any errors!)
You can modify it to use a scanner to input the arguments or even develop it into an applet.
This is the main class then:
import java.util.*;
import java.io.*;
import java.math.*;
public class InputNormalization
{
public static void main(String[] args) throws IOException
{
String originalFile = "numbers.txt"; //PUT THE NAME OF YOUR TEXT FILE HERE
String endFile = "numbersnormalised.txt"; //AND THE TARGET TEXT FILE HERE
int count = 0;
int normalcount = 0;
double num = 0;
double min = 20;
double max = -20;
// double calculatedValue = 0.00;
Scanner fileScan = new Scanner (new File(originalFile));
while (fileScan.hasNext())
{
num = fileScan.nextDouble();
count++;
if (min > num) //Find the minimum value
{
min = num;
}
if (max < num)// Find the maximum value
{
max = num;
}
}
fileScan.close();
fileScan = new Scanner (new File(originalFile));
// new scanner to "rewind" the file
Writer output = null; //for writing to a text file
File file = new File(endFile);
output = new BufferedWriter(new FileWriter(file));
output.write("The number of values in "+originalFile+" is
"+count+"\r\n"); //Number of values in the text file
output.write("The minimum value is "+min+"\r\n");
output.write("The maximum value is "+max+"\r\n");
output.write("The following are the normalized values: \r\n");
double values[] = new double[count];
for (int i = 0; i < values.length; i++)
{
if (fileScan.hasNext())
{
num = fileScan.nextDouble();
if (num == min)
{
output.write("0.00 \r\n");
}
else
{
InputDecimalRounding normalisedValue =
new InputDecimalRounding((num - min)/(max - min));
//Normalize the Data and Round it to 2dp
output.write(normalisedValue+ "\r\n");
}
}
} //END FOR
fileScan.close();
output.close();
} //END MAIN
}//END CLASS
THE INPUTDECIMALROUNDING CLASS FOLLOWS:
import java.text.*;
public class InputDecimalRounding
{
double conversion;
public InputDecimalRounding (double conversion)
{
this.conversion = conversion;
}
public String toString()
{
DecimalFormat normalData = new DecimalFormat("#0.00");
return normalData.format(conversion);
}
}
Donald Trump Success Lessons
- Focus on the Present
“I try to learn from the past, but I plan for the future by focusing exclusively on the present. That’s were the fun is.”
Yesterday is buried, and tomorrow is not yet born; the only progress that can be made toward success has to be done in the present moment, so I recommend that you focus all of your energies into making the present moment as productive as possible. If you don’t, your past will duplicate itself into your future.
- Fail Forward
“Sometimes by losing a battle you find a new way to win the war.”
Never fear failure, failure is the path to success. If at first you don’t succeed, then … that makes sense. Success takes time and it requires failure, through the process of failing you will discover how to succeed. Don’t fear failing, fear not giving your all.
- Think Big
“As long as you’re going to be thinking anyway, think big.”
It takes no more time to think big as it does to think small. Plan for big things in your life, there’s always room at the top for the person who’s willing to think bigger. Leave “little thinking” for people who want to accomplish little things, but not you. Success begins with thinking big.
- Do What You Love
“If you’re interested in ‘balancing’ work and pleasure, stop trying to balance them. Instead make your work more pleasurable.”
I saw a billboard the other day that said, “Life is too short to eat oatmeal,” I don’t know about that, but I do know that life is too short to do work that you despise. Trump said, “I don’t make deals for the money. I’ve got enough, much more than I’ll ever need. I do it, to do it.” Whatever you do, you must do it, to do it, because you will only have success doing what you love!
- Stay Positive
“What separates the winners from the losers is how a person reacts to each new twist of fate.”
Nothing is more constant than “change.” What worked for someone else will not necessarily work for you on your path to success. Challenges that others did not have, you may have. What separates the winners from the losers is that winners react positively to unforeseen challenges. Winners go over the hurdles that stop others.
- Passion is Power
“Without passion you don’t have energy; without energy you have nothing.”
The main ingredient for success is energy. Nothing great can ever be accomplished without “amazing” levels of energy, and energy comes from passion, so what’s the lesson? Always follow your passion, and you will always have the energy to accomplish your dreams.
- Experience is Priceless
“Experience taught me a few things. One is to listen to your gut, no matter how good something sounds on paper. The second is that you’re generally better off sticking with what you know. And the third is that sometimes your best investments are the ones you don’t make.”
You need experience; there are things that experience will teach you that you can’t learn in any other way. Never underestimate the value of getting your hands dirty. With experience come priceless lessons that will position you for success.
What You’ll Wish You’d Known [Part 3]
Ambition
In practice, “stay upwind” reduces to “work on hard problems.” And you can start today. I wish I’d grasped that in high school.
Most people like to be good at what they do. In the so-called real world this need is a powerful force. But high school students rarely benefit from it, because they’re given a fake thing to do. When I was in high school, I let myself believe that my job was to be a high school student. And so I let my need to be good at what I did be satisfied by merely doing well in school.
If you’d asked me in high school what the difference was between high school kids and adults, I’d have said it was that adults had to earn a living. Wrong. It’s that adults take responsibility for themselves. Making a living is only a small part of it. Far more important is to take intellectual responsibility for oneself.
If I had to go through high school again, I’d treat it like a day job. I don’t mean that I’d slack in school. Working at something as a day job doesn’t mean doing it badly. It means not being defined by it. I mean I wouldn’t think of myself as a high school student, just as a musician with a day job as a waiter doesn’t think of himself as a waiter. [3] And when I wasn’t working at my day job I’d start trying to do real work.
When I ask people what they regret most about high school, they nearly all say the same thing: that they wasted so much time. If you’re wondering what you’re doing now that you’ll regret most later, that’s probably it. [4]
Some people say this is inevitable– that high school students aren’t capable of getting anything done yet. But I don’t think this is true. And the proof is that you’re bored. You probably weren’t bored when you were eight. When you’re eight it’s called “playing” instead of “hanging out,” but it’s the same thing. And when I was eight, I was rarely bored. Give me a back yard and a few other kids and I could play all day.
The reason this got stale in middle school and high school, I now realize, is that I was ready for something else. Childhood was getting old.
I’m not saying you shouldn’t hang out with your friends– that you should all become humorless little robots who do nothing but work. Hanging out with friends is like chocolate cake. You enjoy it more if you eat it occasionally than if you eat nothing but chocolate cake for every meal. No matter how much you like chocolate cake, you’ll be pretty queasy after the third meal of it. And that’s what the malaise one feels in high school is: mental queasiness. [5]
You may be thinking, we have to do more than get good grades. We have to have extracurricular activities. But you know perfectly well how bogus most of these are. Collecting donations for a charity is an admirable thing to do, but it’s not hard. It’s not getting something done. What I mean by getting something done is learning how to write well, or how to program computers, or what life was really like in preindustrial societies, or how to draw the human face from life. This sort of thing rarely translates into a line item on a college application.
What You’ll Wish You’d Known [Part 2]
Upwind
I think the solution is to work in the other direction. Instead of working back from a goal, work forward from promising situations. This is what most successful people actually do anyway.
In the graduation-speech approach, you decide where you want to be in twenty years, and then ask: what should I do now to get there? I propose instead that you don’t commit to anything in the future, but just look at the options available now, and choose those that will give you the most promising range of options afterward.
It’s not so important what you work on, so long as you’re not wasting your time. Work on things that interest you and increase your options, and worry later about which you’ll take.
Suppose you’re a college freshman deciding whether to major in math or economics. Well, math will give you more options: you can go into almost any field from math. If you major in math it will be easy to get into grad school in economics, but if you major in economics it will be hard to get into grad school in math.
Flying a glider is a good metaphor here. Because a glider doesn’t have an engine, you can’t fly into the wind without losing a lot of altitude. If you let yourself get far downwind of good places to land, your options narrow uncomfortably. As a rule you want to stay upwind. So I propose that as a replacement for “don’t give up on your dreams.” Stay upwind.
How do you do that, though? Even if math is upwind of economics, how are you supposed to know that as a high school student?
Well, you don’t, and that’s what you need to find out. Look for smart people and hard problems. Smart people tend to clump together, and if you can find such a clump, it’s probably worthwhile to join it. But it’s not straightforward to find these, because there is a lot of faking going on.
To a newly arrived undergraduate, all university departments look much the same. The professors all seem forbiddingly intellectual and publish papers unintelligible to outsiders. But while in some fields the papers are unintelligible because they’re full of hard ideas, in others they’re deliberately written in an obscure way to seem as if they’re saying something important. This may seem a scandalous proposition, but it has been experimentally verified, in the famous Social Text affair. Suspecting that the papers published by literary theorists were often just intellectual-sounding nonsense, a physicist deliberately wrote a paper full of intellectual-sounding nonsense, and submitted it to a literary theory journal, which published it.
The best protection is always to be working on hard problems. Writing novels is hard. Reading novels isn’t. Hard means worry: if you’re not worrying that something you’re making will come out badly, or that you won’t be able to understand something you’re studying, then it isn’t hard enough. There has to be suspense.
Well, this seems a grim view of the world, you may think. What I’m telling you is that you should worry? Yes, but it’s not as bad as it sounds. It’s exhilarating to overcome worries. You don’t see faces much happier than people winning gold medals. And you know why they’re so happy? Relief.
I’m not saying this is the only way to be happy. Just that some kinds of worry are not as bad as they sound.
What You’ll Wish You’d Known [Part 1]
(From a high school talk)
If I were back in high school and someone asked about my plans, I’d say that my first priority was to learn what the options were. You don’t need to be in a rush to choose your life’s work. What you need to do is discover what you like. You have to work on stuff you like if you want to be good at what you do.
It might seem that nothing would be easier than deciding what you like, but it turns out to be hard, partly because it’s hard to get an accurate picture of most jobs. Being a doctor is not the way it’s portrayed on TV. Fortunately you can also watch real doctors, by volunteering in hospitals. [1]
But there are other jobs you can’t learn about, because no one is doing them yet. Most of the work I’ve done in the last ten years didn’t exist when I was in high school. The world changes fast, and the rate at which it changes is itself speeding up. In such a world it’s not a good idea to have fixed plans.
And yet every May, speakers all over the country fire up the Standard Graduation Speech, the theme of which is: don’t give up on your dreams. I know what they mean, but this is a bad way to put it, because it implies you’re supposed to be bound by some plan you made early on. The computer world has a name for this: premature optimization. And it is synonymous with disaster. These speakers would do better to say simply, don’t give up.
What they really mean is, don’t get demoralized. Don’t think that you can’t do what other people can. And I agree you shouldn’t underestimate your potential. People who’ve done great things tend to seem as if they were a race apart. And most biographies only exaggerate this illusion, partly due to the worshipful attitude biographers inevitably sink into, and partly because, knowing how the story ends, they can’t help streamlining the plot till it seems like the subject’s life was a matter of destiny, the mere unfolding of some innate genius. In fact I suspect if you had the sixteen year old Shakespeare or Einstein in school with you, they’d seem impressive, but not totally unlike your other friends.
Which is an uncomfortable thought. If they were just like us, then they had to work very hard to do what they did. And that’s one reason we like to believe in genius. It gives us an excuse for being lazy. If these guys were able to do what they did only because of some magic Shakespeareness or Einsteinness, then it’s not our fault if we can’t do something as good.
I’m not saying there’s no such thing as genius. But if you’re trying to choose between two theories and one gives you an excuse for being lazy, the other one is probably right.
So far we’ve cut the Standard Graduation Speech down from “don’t give up on your dreams” to “what someone else can do, you can do.” But it needs to be cut still further. There is some variation in natural ability. Most people overestimate its role, but it does exist. If I were talking to a guy four feet tall whose ambition was to play in the NBA, I’d feel pretty stupid saying, you can do anything if you really try. [2]
We need to cut the Standard Graduation Speech down to, “what someone else with your abilities can do, you can do; and don’t underestimate your abilities.” But as so often happens, the closer you get to the truth, the messier your sentence gets. We’ve taken a nice, neat (but wrong) slogan, and churned it up like a mud puddle. It doesn’t make a very good speech any more. But worse still, it doesn’t tell you what to do any more. Someone with your abilities? What are your abilities?












