I wan't to generate a fictional job title from some information I have about the visitor.
For this, I have a table of about 30 different job titles:
01 CEO
02 CFO
03 Key Account Manager
...
29 Window Cleaner
30 Dishwasher
I'm trying to find a way to generate one of these titles from a few different variables like name, age, education history, work history and so on. I wan't it to be somewhat random but still consistent so that the same variables always result in the same title.
I also wan't the different variables to have some impact on the result. Lower numbers are "better" jobs and higher numbers are "worse" jobs, but it doesn't have to be very accurate, just not completely random.
So take these two people as an example.
Name: Joe Smith
Number of previous employers: 10
Number of years education: 8
Age: 56
Name: Samantha Smith
Number of previous employers: 1
Number of years education: 0
Age: 19
Now the reason I wan't the name in there is to have a bit of randomness, so that two co-workers of the same age with the same background doesn't get exactly the same title. So I was thinking of using the number of letters in the name to mix it up a bit.
Now I can generate consistent numbers in an infinite number of ways, like the number of letters in the name * age * years of education * number of employers. This would come out as 35 840 for Joe Smith and 247 for Samantha Smith. But I wan't it to be a number between 1-30 where Samantha is closer to 25-30 and Joe is closer to 1-5.
Maybe this is more of a math problem than a programming problem, but I have seen a lot of "What's your pirate name?" and similar apps out there and I can't figure out how they work. "What's your pirate name?" might be a bad example, since it's probably completely random and I wan't my variables to matter some, but the idea is the same.
What I have tried
I tried adding weights to variable groups so I would get an easier number to use in my calculations.
Age
01-20 5
20-30 4
30-40 3
40-50 2
...
Years of education
00-01 0
01-02 1
02-03 2
04-05 3
...
Add them together and play around with those numbers, but there was a lot of problems like everyone ending up in pretty much the same mid-range (no one got to be CEO or dishwasher, everyone was somewhere in the middle), not to mention how messy the code was.
Is there a good way to accomplish what I want to do without having to build a massive math engine?
int numberOfTitles = 30;
var semiRandomID = person.Name.GetHashCode()
^ person.NumberOfPreviousEmployers.GetHashCode()
^ person.NumberOfYearsEducation.GetHashCode()
^ person.Age.GetHashCode();
var semiRandomTitle = Math.Abs(semiRandomID) % numberOfTitles;
// adjust semiRandomTitle as you see fit
semiRandomTitle += ((person.Age / 10) - 2);
semiRandomTitle += (person.NumberOfYearsEducation / 2);
The semiRandomID is a number that is generated from unique hashes of each component. The numbers are unique so that you will always generate the same number for "Joe" for example, but they don't mean anything. It's just a number. So we take all those unique numbers and generate one job title out of the 30 available. Every person has the same chance to get each job title (probably some math freak will proof that there's egde cases to the contrary, but for all practical, non-cryptographic means, it's sufficient).
Now each person has one job title assigned that looks random. However, as it's math and not randomness, they will get the same every time.
Now lets assume Joe got Taxi-Driver, the number 20. However, he has 10 years of formal education, so you decide you want to have that aspect have some weight. You could just add the years onto the job title number, but that would make anyone with 30 years of college parties CEO, so you decide (arbitrarily) that each year of education counts for half a job title. You add (NumberOfYearsEducation / 2) to the job title.
Lets assume Jane got CIO, the number 5. However, she is only 22 years old, a little young to be that high on the list. Again, you could just add the years onto the job title number, but that would make anyone with 30 years of age a CEO, so you decide (arbitrarily) that each year counts as 1/10 of a job title. In addition, you think that being very young should instead subtract from the job title. All years below the first 20 should indeed be a negative weight. So the formula would be ((Age / 10) - 2). One point for each 10 years of age, with the first 2 counting as negative.
Related
This question already has answers here:
How can I divide two integers to get a double?
(9 answers)
Closed 28 days ago.
`This is my second week of my first Computer Science class so I apologize for what is a very basic question:
"Design and implement a program that asks the user to enter the number of programming majors and the total number of students in a class. The program should display that percentage of the class that is majoring in programming. "
I've spent about four hours on this now and I thought I was getting there using past problems I've solved and changing up the coding but this is what I have and it just gives me zero for an answer no matter what.
Any help would be greatly appreciated!
https://dotnetfiddle.net/P6onoF
Is the code I am using
I just get zero for an answer no matter what I enter`
Right.
You shouldn't be asking these questions here because the whole point of going to school is to actually learn it instead of asking the solution, BUT, been there, done that... so here we go :D
There's a couple of things you're doing wrong.
integers "don't divide" (they do, but they sort of don't), you won't get decimal values from them so 1 divided by 2 is 0 although mathematically is 0.5.
If you're gonna use int you need to cast the final to a double, you're using int total = programmingMajors/studentsTotal; so this is an integer. If you have a total of 10 students, with 5 majors. 5/10 = 0.5 with decimals, 0 in integer. Change it to (double)majors/total and you'll have the 0.5 you need.
You're not really getting the percentage of the students just dividing the value. To get the percentage you need to use rule of three.
If 1000 students are 100% of the students, X majors are Y% of them.
e.g. 1000 students. 50 majors.
1000 students = 100 percent.
50 students = X
1000x = 100 * 50
1000x = 5000
x = 5000 / 1000
x = 5
In one single line would be var result = (100 * majors) / total
When using types such as int, doubles and decimals always check their range. Use this microsoft ref. After changing to double and use rule of three.
I ended up not showing how to do it in your code.
// just change the last line to this.
Console.WriteLine("The percent is: " + (100 * programmingMajors) / studentsTotal);
I would suggest write the formula out on a piece of paper first so one has an idea of what one is trying to code.
Also, as mentioned integer values do not have a decimal place, so consider using a different data type such as 'double'.
Also, in terms of display, there is an output formatter 'P' which can be used to format numbers as a percentage.
I have list of billions of items in SQL which can be shuffled by user at random, by moving them inside list to another position, I consider using simple double divide solution:
Id, Rank
1 10
2 20
3 30
4 40
5 50
Now user moves item id=3 to first position and I perform item rank recalculation based on their adjasent items (0 - means no relative from left, max - no relative from right):
Id, Rank
3 (0+10)/2 = 5
1 10
2 20
4 40
5 50
Now there is a bug - until it reach epsilon for double, it will work, after that you will get a couple of elements with epsilon and they are not possible to move.
This can be avoided by infrequent recalculation of stack rank for entire collection, but I hesitate at the moment to implement this, because this looks too much.
I wanted to know is there some other algorithmic solution other than changing billions of items or is there a well-known name to this problem to find appropriate solution myself.
Preface: I'm currently learning about ANNs because I have ~18.5k images in ~83 classes. They will be used to train a ANN to recognize approximately equal images in realtime. I followed the image example in the book, but it doesn't work for me. So I'm going back to the beginning as I've likely missed something.
I took the Encog XOR example and extended it to teach it how to add numbers less than 100. So far, the results are mixed, even for exact input after training.
Inputs (normalized from 100): 0+0, 1+2, 3+4, 5+6, 7+8, 1+1, 2+2, 7.5+7.5, 7+7, 50+50, 20+20.
Outputs are the numbers added, then normalized to 100.
After training 100,000 times, some sample output from input data:
0+0=1E-18 (great!)
1+2=6.95
3+4=7.99 (so close!)
5+6=9.33
7+8=11.03
1+1=6.70
2+2=7.16
7.5+7.5=10.94
7+7=10.48
50+50=99.99 (woo!)
20+20=41.27 (close enough)
From cherry-picked unseen data:
2+4=7.75
6+8=10.65
4+6=9.02
4+8=9.91
25+75=99.99 (!!)
21+21=87.41 (?)
I've messed with layers, neuron numbers, and [Resilient|Back]Propagation, but I'm not entirely sure if it's getting better or worse. With the above data, the layers are 2, 6, 1.
I have no frame of reference for judging this. Is this normal? Do I have not enough input? Is my data not complete or random enough, or too weighted?
You are not the first one to ask this. It seems logical to teach an ANN to add. We teach them to function as logic gates, why not addition/multiplication operators. I can't answer this completely, because I have not researched it myself to see how well an ANN performs in this situation.
If you are just teaching addition or multiplication, you might have best results with a linear output and no hidden layer. For example, to learn to add, the two weights would need to be 1.0 and the bias weight would have to go to zero:
linear( (input1 * w1) + (input2 * w2) + bias) =
becomes
linear( (input1 * 1.0) + (input2 * 1.0) + (0.0) ) =
Training a sigmoid or tanh might be more problematic. The weights/bias and hidden layer would basically have to undo the sigmoid to truely get back to an addition like above.
I think part of the problem is that the neural network is recognizing patterns, not really learning math.
ANN can learn arbitrary function, including all arithmetics. For example, it was proved that addition of N numbers can be computed by polynomial-size network of depth 2. One way to teach NN arithmetics is to use binary representation (i.e. not normalized input from 100, but a set of input neurons each representing one binary digit, and same representation for output). This way you will be able to implement addition and other arithmetics. See this paper for further discussion and description of ANN topologies used in learning arithmetics.
PS. If you want to work with image recognition, its not good idea to start practicing with your original dataset. Try some well-studied dataset like MNIST, where it is known what results can be expected from correctly implemented algorithms. After mastering classical examples, you can move to work with your own data.
I am in the middle of a demo that makes the computer to learn how to multiply and I share my progress on this: as Jeff suggested I used the Linear approach and in particular ADALINE. At this moment my program "knows" how to multiply by 5. This is the output I am getting:
1 x 5 ~= 5.17716232607829
2 x 5 ~= 10.147218373698
3 x 5 ~= 15.1172744213176
4 x 5 ~= 20.0873304689373
5 x 5 ~= 25.057386516557
6 x 5 ~= 30.0274425641767
7 x 5 ~= 34.9974986117963
8 x 5 ~= 39.967554659416
9 x 5 ~= 44.9376107070357
10 x 5 ~= 49.9076667546553
Let me know if you are interested in this demo. I'd be happy to share.
I am taking a BlueJ (terminal for c#) class in high school and I have a programming practice problem that I can't figure out.
Write a program that has the computer randomly choose three numbers from the range 1 to 50. Have the computer produce the output as shown.
The first number chosen is 35
The second number chosen is 23
The third number chosen is 6
From lowest to highest: 6 23 35
The part I don't get is figuring out how display the variables in order from lowest to highest. I'm only supposed to use IF statements, no arrays or loops. (We aren't far enough in the course to use those)
If you can only use if or else if, then use the fact that there are six possible ways that three numbers can be permuted (FIRST = equals first number entered, SECOND = second number, THIRD = third number):
FIRST SECOND THIRD
FIRST THIRD SECOND
SECOND FIRST THIRD
SECOND THIRD FIRST
THIRD FIRST SECOND
THIRD SECOND FIRST
Because this is homework, I won't give you the code, but once you figure out the first line, it's trivial to do the other five. So, start by writing an if statement to capture the FIRST SECOND THIRD situation. (For example, if the user entered 5 10 15, in that order). Hint: use <= (less than or equals operator).
I would suggest grabbing a deck of cards it is great to think out problems like this and just talk your way through it.
If that doesn't fancy you and you just want an answer and not have to think about it, but this won't help you in the long run if you really want to learn.
http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap03/sort.html
I need to convert Day of the Month to how a person would say it.
For instance 4/26 would be spoken as Twenty-Sixth.
4/01 would be spoken as First.
I know I could use a look up table string foo = {"First", "Second", ...}
then take the day of the Month number and pull out the string.
Is there a better way to do this?
In general, yes, you can encode the rules of English to produce ordinal numbers. However, the first nineteen words will inevitably end up in a lookup table, because they are exceptions.
In case of numbering days of the month, the range of exceptional values (1 through 19) covers roughly 60% of the total number of word sequences that you need to produce, so it would make sense to skip the algorithm altogether, and put everything in a lookup table. This would improve readability, and simplify internationalization in case you decide to support languages other than English.
There's no way around a lookup table (even if it's provided by a third party). But you can reduce the number of cases:
One entry for numbers 1-20 and 30 (as spoken in the date).
The missing numbers can be combined, e.g. using 20 + 1, 20 + 2, 30 + 1, etc.