/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package systole.processor.correlation;
import java.math.BigDecimal;
import systole.domain.analysis.results.AnalysisResult;
import systole.domain.analysis.results.ParameterAOD;
import systole.domain.analysis.results.ParameterAOS;
import systole.domain.analysis.results.ParameterIAR;
import systole.domain.signals.FinalSignal;
import systole.domain.signals.Segment;
import systole.math.MathUtils;
import systole.math.SimpleDerivative;
import systole.processor.SignalAnalyzer;
import systole.processor.SignalProcessor;
/**
*
* @author jmj
*/
public class CorrelationByResult extends Correlation {
private AnalysisResult patternAnalysis;
private int ceofAOD = 5;
private int coefAOS = 3;
private int coefIAR = 2;
private int amount = coefIAR + coefAOS + ceofAOD;
/**
*
* @param segment
*/
public CorrelationByResult(Segment segment) {
super(segment);
SignalProcessor processor = new SignalProcessor();
FinalSignal finalSignal = processor.calcDerivatives(segment, new SimpleDerivative());
SignalAnalyzer analyzer = new SignalAnalyzer(BigDecimal.ONE, finalSignal, 0);
this.patternAnalysis = analyzer.calculateParameters();
}
/**
* @param segment
* @return correlation of segment
*/
public BigDecimal correlate(Segment segment) {
BigDecimal aod = this.correlationByAOD(segment);
BigDecimal aos = this.correlationByAOS(segment);
BigDecimal iar = this.correlationByIAR(segment);
BigDecimal totalCorrelation = ((aod.multiply(new BigDecimal(this.ceofAOD))).add(aos.multiply(new BigDecimal(this.coefAOS)).add(iar))).divide(new BigDecimal(amount), MathUtils.CONTEXT);
return totalCorrelation;
}
protected BigDecimal correlationByAOD(Segment segment) {
ParameterAOD aod = this.patternAnalysis.getAod();
// tomo los puntos de AOD
int initOfAOD = aod.getInitPos().getxCoord().intValue();
int endOfAOD = aod.getEndPos().getxCoord().intValue();
// desplazo el inicio 10 pts atras para tener mas puntos en cuenta
initOfAOD -= 10;
// desplazo el fin 10 pts para tener mas puntos en cuenta
endOfAOD += 10;
// calculo la correlación de esa sección
return this.correlate(segment, initOfAOD, endOfAOD);
//return (cor.isNaN() ? 0 : cor.doubleValue());
}
protected BigDecimal correlationByIAR(Segment segment) {
ParameterIAR iar = this.patternAnalysis.getIar();
// tomo los puntos de IAR
int initOfIAR = iar.getInitPos().getxCoord().intValue();
int endOfIAR = iar.getEndPos().getxCoord().intValue();
// desplazo el inicio 10 pts atras para tener mas puntos en cuenta
initOfIAR -= 15;
// desplazo el fin 10 pts para tener mas puntos en cuenta
endOfIAR += 15;
// calculo la correlación de esa sección
return this.correlate(segment, initOfIAR, endOfIAR);
//return (cor.isNaN() ? 0 : cor.doubleValue());
}
protected BigDecimal correlationByAOS(Segment segment) {
ParameterAOS aos = this.patternAnalysis.getAos();
// tomo los puntos de AOS
int initOfIAR = aos.getInitPos().getxCoord().intValue();
int endOfIAR = aos.getEndPos().getxCoord().intValue();
// calculo la correlación de esa sección
return this.correlate(segment, initOfIAR, endOfIAR);
//return (cor.isNaN() ? 0 : cor.doubleValue());
}
}