public OutputData learn(InputData id, Target tg, int k, String task) { this.k = k; OutputData ret; this.col = id.getCol(); this.row = id.getRow(); this.groupNum = id.getGroup(); this.task = task; this.groupRangeUpperLimit = id.getGroupRangeUpperLimit(); init(); int t = 0; for (int iter = 0; iter < 100; iter++) { // tmp System.out.println(iter); // *********************** double diff = 0; for (int p = 0; p < id.getRow(); p++, t++) { // double tmpEta = eater / (t0 + t*0.1); // double tmpEta = eater / Math.pow((t + 1), power_t); double eta = 0.005; Map<Integer, Double> record = id.getOneRecord(p); // pick up one record double y = tg.getOneTarget(p); // pickup the target for the chosen record w0 = w0 - eta * (calcGrad(0, record, y, "w0") + 2 * lambda0 * w0); // System.out.println("w0:" + w0);//************** for (int i : record.keySet()) { double gradWi = calcGrad(i, record, y, "w"); // dloss(predict("w", i), y); int pi = pi(i); double nextWi = w[i] - eta * (gradWi + 2 * lambdaW.get(pi) * w[i]); w[i] = nextWi; for (int f = 0; f < k; f++) { double gradVij = dloss( predict(y, record), y, i, f, "v", record); // calcGradV(i, f, pi, y, "v"); // dloss(predict("v", i, f), y) // System.out.println("key:" + key + ", f:" + f + ", groupOfKey:" + groupOfKey); // //****************** V[i][f] -= eta * (gradVij + 2 * lambdaV[f][pi] * V[i][f]); // System.out.println("V[key][f]:" + V[key][f]); //*************** } } if (task.equals("regression")) { double pred = predict(y, record); double d = y - pred; diff += d * d; } else if (task.equals("classification")) { if (y != predict(y, record)) { // System.out.println("tg:" + this.tg + ", predict:" + predict()); //**** diff++; } } } // effect evaluation results.add(diff); } System.out.println(results); // **** ret = new OutputData(w0, w, V); return ret; }