org.protempa.proposition.stats.AbstractKaplanMeyer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protempa-framework Show documentation
Show all versions of protempa-framework Show documentation
Protempa Framework is the core of Protempa.
/*
* #%L
* Protempa Framework
* %%
* Copyright (C) 2012 - 2013 Emory University
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://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.
* #L%
*/
package org.protempa.proposition.stats;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.protempa.proposition.AbstractParameter;
import org.protempa.proposition.visitor.AbstractPropositionVisitor;
import org.protempa.proposition.Event;
import org.protempa.proposition.PrimitiveParameter;
import org.protempa.proposition.TemporalParameter;
import org.protempa.proposition.TemporalProposition;
import org.protempa.proposition.value.Unit;
import org.protempa.proposition.value.Value;
/**
* Calculates length frequencies of temporal propositions.
*
* @author Andrew Post
*
*/
public abstract class AbstractKaplanMeyer extends AbstractPropositionVisitor {
private final Map> survival;
private final Unit targetLengthUnit;
static class SurvivalKey {
private String id;
private Value value;
private volatile int hashCode = 0;
SurvivalKey(String id, Value value) {
this.id = id;
this.value = value;
}
public String getId() {
return this.id;
}
public Value getValue() {
return this.value;
}
@Override
public int hashCode() {
if (hashCode == 0) {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result
+ ((value == null) ? 0 : value.hashCode());
hashCode = result;
}
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof SurvivalKey)) {
return false;
}
final SurvivalKey other = (SurvivalKey) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
@Override
public String toString() {
return "SurvivalKey: id=" + this.id + "; value=" + this.value;
}
}
static class LengthProportionPair {
private long length;
private float proportion;
LengthProportionPair(long length, float proportion) {
this.length = length;
this.proportion = proportion;
}
public long getLength() {
return this.length;
}
public float getProportion() {
return this.proportion;
}
@Override
public String toString() {
return "Bin: length=" + this.length + "; proportion="
+ this.proportion;
}
}
AbstractKaplanMeyer() {
this(null);
}
AbstractKaplanMeyer(Unit targetLengthUnit) {
this.survival = new HashMap<>();
this.targetLengthUnit = targetLengthUnit;
}
public final LengthProportionPair[] getSurvivalCurveData() {
Collection