public static void main(final String[] args) throws ParseException { final PublicFactorSet set = new PublicFactorSet(); // ["ConsumersCottage", "ConsumersLegal", "ConsumersFlat", "DateTime", "Event", // "Temperature", "Consumers"] // 114296373,ConsumersCottage=2474,ConsumersLegal=537,ConsumersFlat=6986,DateTime=2010.01.01 PublicFactor f = new PublicFactor(); f.setName("ConsumersCottage"); f.setValue("2474"); set.getFactors().add(f); f = new PublicFactor(); f.setName("ConsumersLegal"); f.setValue("537"); set.getFactors().add(f); f = new PublicFactor(); f.setName("ConsumersFlat"); f.setValue("6986"); set.getFactors().add(f); f = new PublicFactor(); f.setName("DateTime"); f.setValue("2010.01.01 19"); set.getFactors().add(f); f = new PublicFactor(); f.setName("Event"); f.setValue(""); set.getFactors().add(f); f = new PublicFactor(); f.setName("Temperature"); f.setValue("-4"); set.getFactors().add(f); f = new PublicFactor(); f.setName("Consumers"); f.setValue("9997"); set.getFactors().add(f); // 2474 537 6986 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 // 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 -4 System.out.println("Result: " + generate(set)); }
public static long generate(final PublicFactorSet set) throws ParseException { // long long int consumage = [[scanner nextElement] longLongValue]; // long long int cottage = [[[scanner nextElement] componentsSeparatedByString:@"="][1] // longLongValue]; // long long int legal = [[[scanner nextElement] componentsSeparatedByString:@"="][1] // longLongValue]; // long long int flat = [[[scanner nextElement] componentsSeparatedByString:@"="][1] // longLongValue]; // NSString * dateTime = [[scanner nextElement] componentsSeparatedByString:@"="][1]; // NSString * event = [[scanner nextElement] componentsSeparatedByString:@"="][1]; // long long int temperature = [[[scanner nextElement] componentsSeparatedByString:@"="][1] // longLongValue]; // long long int consumers = [[[scanner nextElement] componentsSeparatedByString:@"="][1] // longLongValue]; // long long int failures = [[[scanner nextElement] componentsSeparatedByString:@"="][1] // longLongValue]; // BOOL failure = [[scanner nextElement] rangeOfString:@"false"].location == NSNotFound; final Map<String, PublicFactor> factors = new HashMap<>(); for (final PublicFactor f : set.getFactors()) { factors.put(f.getName(), f); } // <factors name="ConsumersCottage">3572</factors> // <factors name="ConsumersLegal">763</factors> // <factors name="ConsumersFlat">9830</factors> // <factors name="DateTime">2013.02.03 05</factors> // <factors name="Event">SHOW</factors> // <factors name="Temperature">-6</factors> // <factors name="Consumers">14165</factors> final double cottage = getValue(factors, "ConsumersCottage"); final double legal = getValue(factors, "ConsumersLegal"); final double flat = getValue(factors, "ConsumersFlat"); final double temperature = getValue(factors, "Temperature"); final double consumers = getValue(factors, "Consumers"); final String event = factors.get("Event").getValue(); final Date dateTime = new SimpleDateFormat("yyyy.MM.dd HH").parse(factors.get("DateTime").getValue()); final Calendar dateCal = Calendar.getInstance(); dateCal.setTime(dateTime); final int year = dateCal.get(Calendar.YEAR); final int month = dateCal.get(Calendar.MONTH) + 1; final int day = dateCal.get(Calendar.DAY_OF_MONTH); final int hour = dateCal.get(Calendar.HOUR_OF_DAY); final int weekDay = dateCal.get(Calendar.DAY_OF_WEEK); final List<Double> input = new ArrayList<>(); input.addAll(Arrays.asList(cottage, legal, flat)); for (int i = 1; i <= 12; i++) { if (i == month) { input.add(1D); } else { input.add(0D); } } for (int i = 1; i <= 31; i++) { if (i == day) { input.add(1D); } else { input.add(0D); } } for (int i = 1; i <= 7; i++) { if (i == weekDay) { input.add(1D); } else { input.add(0D); } } for (int i = 0; i <= 23; i++) { if (i == hour) { input.add(1D); } else { input.add(0D); } } if ("SPORT".equalsIgnoreCase(event)) { input.add(1D); } else { input.add(0D); } if ("SHOW".equalsIgnoreCase(event)) { input.add(1D); } else { input.add(0D); } input.add(temperature); // final ArrayList<Double> superArray = new ArrayList<>(Arrays.<Double>asList(2474D, 537D, // 6986D, 1D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 1D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, // 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, // 0D, 0D, 0D, 0D, 1D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, 0D, // 0D, 0D, 1D, 0D, 0D, 0D, 0D, 0D, 0D, -4D)); // // System.out.println("Eq: " + superArray.equals(input)); // (t-mu)./sigma // [16:28:44] (Stanfy) Taykalo Paul aka Kilew: X_norm = (X .- (t * mu)) ./ (t * sigma); System.out.println(input.toString()); for (int i = 0; i < input.size(); i++) { input.set(i, (input.get(i) - mu[i]) / sigma[i]); } input.add(0, 1D); System.out.println(input.toString()); double resultMul = 0; for (int i = 0; i < input.size(); i++) { resultMul += input.get(i) * values[i]; } System.out.println(values.length + " vs " + input.size()); System.out.println(mu.length + " vs " + sigma.length); return Math.round(resultMul); }