Text reproduced here 3-1-12d2140
2015-01-13azim58 - Text reproduced here 3-1-12d2140
import java.util.ArrayList;
import java.util.Collections;
public class NormalizedDataHandler
public static void main(String[] args) {
NormalizedDataHandler normalized_data_handler = new
NormalizedDataHandler();
normalized_data_handler.testconvertNormalizedDataToIntegersFromXToY();
public void testconvertNormalizedDataToIntegersFromXToY()
ArrayList list = new ArrayList();
double x1 = 0.3;
double x2 = 0.6;
double x3 = 1.5;
list.add(x1);
list.add(x2);
list.add(x3);
list = convertNormalizedDataToIntegersFromXToY(list, 1, 5);
//the resulting list should be 1,2,5
System.out.println(list);
public ArrayList convertNormalizedDataToIntegersFromXToY(ArrayList list,
int lower_bound, int upper_bound)
double current_min =
Double.valueOf(Collections.min(list).toString()).doubleValue();
double current_max =
Double.valueOf(Collections.max(list).toString()).doubleValue();
ArrayList new_list = new ArrayList();
for(int i=0; i<list.size(); i++)
{
double current_number =
Double.valueOf(list.get(i).toString()).doubleValue();
double current_range = current_max-current_min;
double new_range = upper_bound-lower_bound;
double new_number =
((current_number-current_min)/current_range)*new_range+lower_bound;
int i_new_number = Double.valueOf(new_number).intValue();
new_list.add(i_new_number);
return new_list;
}
}