/** * Copy. * * @return the instance */ @Override public Instance copy() { InstanceImpl inst = new InstanceImpl(this); return inst; }
Instance inst = new InstanceImpl(1, attributes); inst.setDataset(this.ltm); this.ltm.add(inst);
@Override public Instance sourceInstanceToTarget(Instance sourceInstance) { double [] attValues = new double[targetInstances.numAttributes()]; Instance newInstance=new InstanceImpl(sourceInstance.weight(),attValues); for (int i=0; i<this.targetInputIndices.length; i++){ newInstance.setValue(i, sourceInstance.valueInputAttribute(targetInputIndices[i])); } for (int i=0; i<this.targetOutputIndices.length; i++){ newInstance.setValue(i, sourceInstance.valueOutputAttribute(targetOutputIndices[i])); } newInstance.setDataset(targetInstances); return newInstance; }
@Override public InstanceExample nextInstance() { Instance x = (Instance) ((Instance) this.inputStream.nextInstance().getData()); if(dataset==null){ System.out.println("INIT. "); initialize(x); } double z_[] = new double[dataset.numAttributes()]; Instance z = new InstanceImpl(x.weight(),z_); int d = x.numAttributes(); int h = numLatentOption.getValue(); int j_c = x.classIndex(); for(int k = 0; k < h; k++) { double sum_k = 0.; for(int j = 0; j < d; j++) { sum_k += (x.value(j) - c[k]); } double v = sum_k / Math.pow(r[k],2); z.setValue(k,Math.exp(-sum_k)); } z.setValue(h,x.classValue()); z.setDataset(dataset); return new InstanceExample(z); }
@Override public Instance sourceInstanceToTarget(Instance sourceInstance) { double [] attValues = new double[targetInstances.numAttributes()]; Instance newInstance=new InstanceImpl(sourceInstance.weight(),attValues); int numInputs=this.targetInstances.numInputAttributes(); for (int i=0; i<numInputs; i++){ newInstance.setValue(i, sourceInstance.valueInputAttribute(i)); } for (int i=0; i<this.targetOutputIndices.length; i++){ newInstance.setValue(numInputs+i, sourceInstance.valueOutputAttribute(targetOutputIndices[i])); } newInstance.setDataset(targetInstances); return newInstance; }
/** * Filter an instance. * Assume that the instance has a single class label, as the final attribute. Note that this may not always be the case! * * @param x input instance * @return output instance */ public Instance filterInstance(Instance x) { if(dataset==null){ initialize(x); } double z_[] = new double[H+1]; int d = x.numAttributes() - 1; // suppose one class attribute (at the end) for(int k = 0; k < H; k++) { // for each hidden unit ... double a_k = 0.; // k-th activation (dot product) for(int j = 0; j < d; j++) { a_k += (x.value(j) * W[k][j]); } z_[k] = (a_k > 0. ? a_k : 0.); // <------- can change threshold here } z_[H] = x.classValue(); Instance z = new InstanceImpl(x.weight(),z_); z.setDataset(dataset); return z; }
private Instance processInstance(Instance instance) { double [] attValues = new double[dataset.numAttributes()]; Instance newInstance=new InstanceImpl(instance.weight(),attValues); int count=0; for (int i=0; i<inputsSelected.numEntries(); i++){ int start=inputsSelected.getStart(i)-1; int end=inputsSelected.getEnd(i)-1; for (int j=start; j<=end; j++){ newInstance.setValue(count, instance.value(j)); count++; } } for (int i=0; i<outputsSelected.numEntries(); i++){ int start=outputsSelected.getStart(i)-1; int end=outputsSelected.getEnd(i)-1; for (int j=start; j<=end; j++){ newInstance.setValue(count, instance.value(j)); count++; } } newInstance.setDataset(dataset); return newInstance; }