* working on ALE image pipelines that appear to lose data * transformation pipeline for ALE has been broken for a while and needed some cleanup to make sure that openCV tooling for scene transforms was actually working. * allowing history length to be set and passed through to history merge transforms Signed-off-by: Bam4d <chrisbam4d@gmail.com> * native image loader is not thread-safe so should not be static Signed-off-by: Bam4d <chrisbam4d@gmail.com> * make sure the transformer for encoding observations that are not pixels converts corectly Signed-off-by: Bam4d <chrisbam4d@gmail.com> * Test fixes for ALE pixel observation shape Signed-off-by: Bam4d <chrisbam4d@gmail.com> * Fix compilation errors Signed-off-by: Samuel Audet <samuel.audet@gmail.com> * fixing some post-merge issues, and comments from PR Signed-off-by: Bam4d <chrisbam4d@gmail.com> Co-authored-by: Samuel Audet <samuel.audet@gmail.com>
66 lines
1.8 KiB
Java
66 lines
1.8 KiB
Java
/*******************************************************************************
|
|
* Copyright (c) 2020 Konduit K.K.
|
|
*
|
|
* This program and the accompanying materials are made available under the
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
* https://www.apache.org/licenses/LICENSE-2.0.
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
******************************************************************************/
|
|
|
|
package org.deeplearning4j.rl4j.observation;
|
|
|
|
import lombok.Getter;
|
|
import org.deeplearning4j.rl4j.space.Encodable;
|
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
|
|
|
/**
|
|
* Represent an observation from the environment
|
|
*
|
|
* @author Alexandre Boulanger
|
|
*/
|
|
public class Observation implements Encodable {
|
|
|
|
/**
|
|
* A singleton representing a skipped observation
|
|
*/
|
|
public static Observation SkippedObservation = new Observation(null);
|
|
|
|
/**
|
|
* @return A INDArray containing the data of the observation
|
|
*/
|
|
@Getter
|
|
private final INDArray data;
|
|
|
|
@Override
|
|
public double[] toArray() {
|
|
return data.data().asDouble();
|
|
}
|
|
|
|
public boolean isSkipped() {
|
|
return data == null;
|
|
}
|
|
|
|
public Observation(INDArray data) {
|
|
this.data = data;
|
|
}
|
|
|
|
/**
|
|
* Creates a duplicate instance of the current observation
|
|
* @return
|
|
*/
|
|
public Observation dup() {
|
|
if(data == null) {
|
|
return SkippedObservation;
|
|
}
|
|
|
|
return new Observation(data.dup());
|
|
}
|
|
}
|