对于强化学习,我创建了两个List<INDArray>
状态以及相应的移动预测和奖励值。我怎样才能将这两个List
s 变成一个org.nd4j.linalg.dataset.api.DataSet
问问题
115 次
1 回答
0
大多数方法也接受 org.nd4j.linalg.dataset.api.iterator.DataSetIterator,而不仅仅是 org.nd4j.linalg.dataset.DataSet。所以你可以使用这个代码:
import java.util.ArrayList;
import java.util.List;
import org.nd4j.linalg.dataset.DataSet;
import org.nd4j.linalg.dataset.api.DataSetPreProcessor;
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
public class DataSetIteratorImpl implements DataSetIterator {
private static final long serialVersionUID = -3010080072504907088L;
private List<DataSet> entries;
private int current = 0;
private DataSetPreProcessor dataSetPreProcessor;
public DataSetIteratorImpl() {
entries = new ArrayList<DataSet>();
reset();
}
public void addEntry(DataSet entry) {
entries.add(entry);
}
@Override
public boolean hasNext() {
return current < entries.size();
}
@Override
public DataSet next() {
return entries.get(current++);
}
@Override
public boolean asyncSupported() {
return false;
}
@Override
public int batch() {
return entries.size();
}
@Override
public DataSetPreProcessor getPreProcessor() {
return dataSetPreProcessor;
}
@Override
public void reset() {
current = 0;
}
@Override
public boolean resetSupported() {
return true;
}
@Override
public void setPreProcessor(DataSetPreProcessor _dataSetPreProcessor) {
dataSetPreProcessor = _dataSetPreProcessor;
}
@Override
public int inputColumns() {
throw new UnsupportedOperationException();
}
@Override
public DataSet next(int arg0) {
throw new UnsupportedOperationException();
}
@Override
public List<String> getLabels() {
throw new UnsupportedOperationException();
}
@Override
public int totalOutcomes() {
throw new UnsupportedOperationException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
您可以使用以下代码创建迭代器:
DataSetIterator iterator = new DataSetIteratorImpl ();
然后当你填充迭代器时,只需调用几次:
iterator.addEntry(new DataSet(INDArrayinput, INDArrayoutput));
之后,迭代器就可以用作训练集了。
于 2021-03-06T12:51:53.070 回答