generating random numbers 1 Answer(s) 3 years ago
Posted in : Java Beginners
We would like to be able to predict tomorrow's price of a share of stock. We have data on past daily prices. Based on that we will make a prediction. Our plan is to use a weighted average of the 5 most recent prices as the prediction. We will choose the appropriate weights as the ones that would have best predicted prices in the past. The weights must add up to one to be a weighted average, but some of them may be negative. We will restrict consideration to weights that are chosen from the following 21 values: -1.0, -0.9, ... , -0.1, 0.0, 0.1, ..., 0.9, 1.0 We define the "error" of a prediction to be the absolute value of the difference between the prediction and the price.We will evaluate a possible weighting by using it to predict each of the known prices (except for the first 5, which don't have enough predecessors). We will then choose the weighting that has the smallest average error for its predictions. Before we use our weighted averaging scheme to make our fortune on the stock market we need to have some idea of how well it predicted past data. Create a class Predicting that contains a method avgError that will be given a double[] data and will return the average error made by our best weighting. Definition
Class: Predicting Method: avgError Parameters: double[] Returns: double Method signature: double avgError(double[] data) (be sure your method is public)
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9. Constraints
- data will contain between 6 and 50 elements inclusive. - Each element of data will be between 10.0 and 100.0 inclusive. Examples
0)
{10,10,10,10,10,10} Returns: 0.0 A weighting of .2,.2,.2,.2,.2 will exactly predict the only past price that had 5 predecessors. 1)
{50,10,50,10,50,10,50,10,50,10,50,10} Returns: 0.0 A weighting of -1,0,0,1,1 predicts price correctly every time (in the past). For example, the prediction of the most recent price is -1*50 + 0*10 + 0*50 + 1*10 + 1*50 = 10 which was exactly right. 2)
{50,60,50,60,50,60,60} Returns: 5.0 The best choice of weights is -1.0,-1.0,1.0,1.0,1.0 which gives a prediction of 50 for the next to the last price (-1*50 + -1*60 + 1*50 + 1*60 + 1*50 = 50) and a prediction of 60 for the last price (-1*60 + -1*50 + 1*60 + 1*50 + 1*60 = 60). So the errors are 10 and 0 for the two predictions with an average error of 5. 3)
} public static double[] shiftRight(double[] array, int amount) { for (int j = 0; j < amount; j++) { double a = array[array.length - 1]; int i; for (i = array.length - 1; i > 0; i--) array[i] = array[i - 1]; array[i] = a; } return array; } public static void main(String[] args){ Scanner input=new Scanner(System.in); System.out.println("Enter 10 values:"); double arr[]=new double[10]; for(int i=0;i<arr.length;i++){ arr[i]=input.nextDouble(); } double err=Predicting.avgError(arr); System.out.println(err); } }
Thanks
Related Pages:
generating random numbers - Java Beginners generatingrandom numbers We would like to be able to predict tomorrow's price of a share of stock. We have data on past daily prices. Based on that we will make a prediction. Our plan is to use a weighted average of the 5 most
Generating Random Numbers to Fill array. Java Beginner needing help! GeneratingRandomNumbers to Fill array. Java Beginner needing help!  ... a program that produces random permutations of the numbers 1 to 10. eg... the permuted numbers. Make a second array and fill it with the numbers 1 to 10
Generating Random Number GeneratingRandom Number
In many places you need randomnumbers to fulfill your
requirements. Java provides classes to help you in generation randomnumbers
random numbers random numbers hi.. i am creating a website and on feedback form to authenticate user i want to generate a random number on label.if user types that number correctly in textbox then he is allowed to submit feedback otherwise
Generate Random Numbers
Generate Random Numbers hi,,,
Please give me answer with example
How do you generate randomnumbers within a given limit with actionscript...
This function generate randomnumbers with in given limit
random numbers - Java Beginners random numbers write a program to accept 50 numbers and display 5 numbers randomly Hi Friend,
Try the following code:
import...();
System.out.println("Randomnumbers are: ");
int random[]=new int[5];
for(int i=0;i
Random numbers - Introduction
Java NotesRandom numbers - Introduction
When to use randomnumbers
There are many types of programs that use randomnumbers.
Game programs use them... numbers.
You might want to use randomnumbers to change the
appearance
random numbers - Java Beginners random numbers Hello i need this code to be modified for me to display the randomnumbers, but not twice or more. I mean i need a number...("Randomnumbers are: ");
int random[]=new int[5];
for(int i=0;i Hi
Random numbers - Development process Random numbers hi,
How to generate unique randomnumbers between range like(10 to 50) Hi friend,
class RandomNumber
{
public static void main(String[] args)
{
//set the variable aNumber
Random Numbers - shuffling
is described at the bottom.
Shuffling: Randomnumbers without replacement
The random number methods
generate numbers with replacement. This means... numbers - intro
Randomnumbers - API
Copyleft 2005 Fred Swartz MIT
generate random numbers and display the largest
generate randomnumbers and display the largest Hi, I am using... creates an array and fills it with random ints, prints the contents... ArrayRandom{
public static void main(String args[]){
Random r = new Random
Random numbers - API
class often produce randomnumbers in a more convenient form, but
requires creating... directly useful numbers from the Random class.
java.util.Random class
To use... and standard deviation 1.0
Example: Generating a random Color
To create any color
Random in jsp Random in jsp
Randomnumbers are the numbers that are determined
entirely by chance. User does not have any control over the working of randomnumbers
Javascript random number - Design concepts & design patterns
are retreived from database.I have to generate randomnumbers corresponding to every row.But problem is one constraint is there while generatingrandom numbers.If... one group there will be 10 rows and their randomnumbers will be same.Then next
Generate array of random numbers
Generate array of randomnumbers
You can generate a random number either...() but it is better to use Random class. If you want to generate a series of randomnumbers...();
}
System.out.println();
System.out.println("Randomnumbers are: ");
int random
Generate array of random numbers without repetition
Generate array of randomnumbers without repetition
In the previous section, you have learnt how to generate an array of randomnumbers from the given array... created an application that will generate the array of randomnumbers without
Javascript random number - Design concepts & design patterns
are retreived from database.I have to generate randomnumbers corresponding to every row.But problem is one constraint is there while generatingrandom numbers.If... group there will be 10 rows and their randomnumbers will be same.Then next 10
JavaScript array get elements at random
of the
array. For generatingrandomnumbers we have used the Math.random() function... randomnumbers between
value "0" and "9". Each
and every time...
JavaScript array get elements at random
 
getting random number in java
getting random number in java getting random number in java
Hi everyone, i am trying to get a random number in a particular range. for example randomnumbers between 1 to 100 in Java. Though i m new to Java, i have tried many
RANDOM ACCESS FILE CONCEPT RANDOM ACCESS FILE CONCEPT Write a program to use a File object and print even numbers from two to ten.
Then using RandomAccessFile write numbers from 1 to 5. Then using seek () print
only the last 3 digits
switch Example - Random Insults
Java Notesswitch Example - Random Insults
The following class could be useful for generatingrandom insults
in response to erroneous user input... the logic for generating the insult
in a string. It knows nothing about the user
PHP Random Number
PHP Generate RandomNumbers:
A random number is becoming more useful.... To generate random number, PHP
provides rand() function. ... Value
A random value
Example :
<
understanding buttons :JSP random no program
understanding buttons :JSP random no program I hav java random... random no between 100 and 200 on loading and on clicking submit button it ives... "no is greater"
please help me to understand buttons .thank you
java code for random
MySQL random
and thereafter we can show the result of it. Numbers generated are in the random...
MySQL random
In MySQL we can get the random records by using the method
RAND() of MySQL
generating mock data class of times (start and end time and value) generating mock data class of times (start and end time and value) Using the timertask function want to generate a set of mock data of times using the random DATE class and values for plotting on a graph using java.
How
generating itext pdf from java application - Java Beginners generating itext pdf from java application hi,
Is there any method in page events of itext to remove page numbers from pdf generated frm java application. Hi friend,
Read for more information.
http
MySQL random number
versions of RAND() function : first RAND()
and second is RAND(X). Randomnumbers... is not a perfect random number but it is very
close to the perfect randomnumbers.
Here.... Numbers generated are in the random order which means that they lack any
pattern
Default constructor generate two random equations
Default constructor generate two random equations Need to create a default constructor in a programmer defined class that generates a random question, addition or subtraction. And when adding the numbers must be random from 0-12
Assigning ordinate numbers - JSP-Servlet
,
For random number:
import java.util.*;
public class OrdinalNumber {
public static...[] args) {
OrdinalNumber number = new OrdinalNumber();
Random r=new Random
Randomizer
;
In this example we are discussing how to generate the
randomnumbers... randomnumbers by apply some mathematical operations onto them
and display 10 randomnumbers on the console.
Description of program:
In the given
Random classes Random classes Hello... What is Random class? What's the purpose
Random classes Random classes Hello... What is Random class? What's the purpose
Random classes Random classes Hello... What is Random class? What's the purpose
random number random number Sir could u please send me the code registration form of roseindia.net with image varification
random number random number Please
How do I generate a program that gives me random integer from 115 to 250? Using java.util.random.
Thank you very much!
 ...[] args){
int min = 115;
int max = 250;
Randomrandom = new Random
Generating pdf in Spring Generating pdf in Spring Sir/Madam,
I need your help in generating a pdf by fetching the data form database and by using unicode in spring framework
Pick at Random
the entry from the array before selecting another name at random
Java programming: generating series
Java programming: generating series Write a program to accept a string using buffered reader and replace character sequence 'cat' with 'dog'
Here is a java code that accept the string from the user using
java programming:generating series
java programming:generating series Write a program to generate series:
12345
1234
123
12
1
1
12
123
1234
12345
12345
Here is a code that displays the following pattern:
12345
1234
123
12
1
1
12
123
1234
java programming:generating series
java programming:generating series 12345
1234
123
12
1
1
12
123
1234
12345
Here is a code that displays the following pattern:
12345
1234
123
12
1
1
12
123
1234
12345
class Pattern
{
public
Generating dynamic fields in struts2 Generating dynamic fields in struts2 Hi,
I want generate a web page which should have have some struts 2 tags in a group and a "[+]" button for the group. On click of this button one more group of fields should be generated
java programming:generating series
java programming:generating series 1234554321
1234
4321
123
321
12
21
1
1
Here is a java code that displays the following pattern
1234554321
1234 4321
123 321
12 21
1 1
class Pattern
using random number
using random number generate a 10 digit number using random number and display the length of longest increasing series
Random Access File class Random Access File class Write a short note on Random Access File class.
Please visit the following link:
Java Random Access File
Random data - Java Beginners Random data hi friend,
I want to ask how to make random data. i has example word like this :
Gaza! Gaza! Palestina merdeka!
how to make random like :
Azag! Azag! Anitselap akedrem!
thank's
RANDOM ACCESS FILE CONCEPT RANDOM ACCESS FILE CONCEPT In a random access file, first write the alphabets a,b, c, d till z. Read the file
in reverse order and print it on screen