Skip to content

Commit

Permalink
Contents added and generating buildings with custom contents are added
Browse files Browse the repository at this point in the history
  • Loading branch information
DDred committed Mar 24, 2011
1 parent dbb5082 commit 38d13a4
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/interval_analysis/AverageRemoteness.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void doWork() throws OperatorException {
try {
values[i][0] = (double)i;
values[i][1] = 1.0;//Double.parseDouble(chains.get(i).toString());
values[i][2] = chains.get(i).getCharacteristic(LinkUp.Start, CharacteristicsFactory.getDeltaG());
values[i][2] = chains.get(i).getCharacteristic(LinkUp.Start, CharacteristicsFactory.getAverageRemoteness());
} catch (Exception e) {
Logger.getLogger(AverageRemoteness.class.getName()).log(Level.SEVERE, "It is not impossible to recive average remoteness", e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interval_analysis/chain/BuildingsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public RMChainSet read() throws OperatorException {
@Override
public List<ParameterType> getParameterTypes() {
List<ParameterType> types = super.getParameterTypes();
types.add(new ParameterTypeInt(PARAMETER_CHAIN_LENGTH, "Chain length", 2, 100));
types.add(new ParameterTypeInt(PARAMETER_CHAIN_LENGTH, "Chain length", 1, 100));
types.add(new ParameterTypeInt(PARAMETER_ALPHABET_POWER, "Alphabet power", 1, 100));
return types;
}
Expand Down
42 changes: 37 additions & 5 deletions src/interval_analysis/chain/SamplingDistribution.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import com.rapidminer.example.*;
import com.rapidminer.operator.*;
import com.rapidminer.operator.ports.*;
import com.rapidminer.parameter.ParameterType;
import com.rapidminer.parameter.ParameterTypeInt;
import libiada.Statistics.Picks.CalculatorFactory;
import libiada.Statistics.Picks.Picks;

import java.util.Iterator;
import java.util.List;

/**
* Created by IntelliJ IDEA.
Expand All @@ -16,6 +21,8 @@ public class SamplingDistribution extends Operator {
private OutputPort outPort = getOutputPorts().createPort("sample");
private InputPort inPort = getInputPorts().createPort("distribution");

public static final String PARAMETER_INTERVALS_COUNT = "intervals count";

public SamplingDistribution(OperatorDescription description) {
super(description);
}
Expand All @@ -25,13 +32,38 @@ public void doWork() throws OperatorException {
ExampleSet sample = inPort.getData();
Attributes attributes = sample.getAttributes();

for (Example example : sample) {
Iterator<Attribute> attrIter = attributes.allAttributes();
while (attrIter.hasNext()) {
example.setValue(attrIter.next(), 15.0f);
Iterator<Attribute> attrIter = attributes.allAttributes();
double outValues[][] = new double[getParameterAsInt(PARAMETER_INTERVALS_COUNT)][attributes.size()];
int attrNum = 0;
while (attrIter.hasNext()) {
Attribute attribute = attrIter.next();
Picks picks = new Picks();
for (Example example : sample) {
picks.add(example.getValue(attribute));
}
Picks sampling = picks.calculatePicks(CalculatorFactory.getSampling(getParameterAsInt(PARAMETER_INTERVALS_COUNT)));
sampling.resetIterator();
while (sampling.hasNext()) {
outValues[sampling.getIndex()][attrNum] = sampling.next();
}
attrNum++;
}
ExampleSet outSet = ExampleSetFactory.createExampleSet(outValues);

attrIter = attributes.allAttributes();
int curIndex = 1;
while (attrIter.hasNext()){
outSet.getAttributes().get("att" + curIndex).setName(attrIter.next().getName());
curIndex++;
}

outPort.deliver(sample);
outPort.deliver(outSet);
}

@Override
public List<ParameterType> getParameterTypes() {
List<ParameterType> types = super.getParameterTypes();
types.add(new ParameterTypeInt(PARAMETER_INTERVALS_COUNT, "Chain length", 2, 1000));
return types;
}
}
25 changes: 25 additions & 0 deletions src/libiada/IntervalAnalysis/Buildings/BuildingsGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package libiada.IntervalAnalysis.Buildings;

import libiada.IntervalAnalysis.Chain;

import java.util.ArrayList;

/**
* Created by IntelliJ IDEA.
* User: Alex
* Date: 25.03.11
* Time: 2:41
*/
public class BuildingsGenerator {
public ArrayList<String> GetBuildings(int chainLength, int alphabetPower) {
Tree tree = new Tree();
tree.rebuildTreeForBuildings(chainLength, alphabetPower);
return tree.getBuildingsAsStrings();
}

public ArrayList<String> GetBuildings(Contents contents) throws Exception {
Tree tree = new Tree();
tree.rebuildTreeForBuildings(contents);
return tree.getBuildingsAsStrings();
}
}
67 changes: 67 additions & 0 deletions src/libiada/IntervalAnalysis/Buildings/Contents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package libiada.IntervalAnalysis.Buildings;

import libiada.Root.IBaseObject;
import libiada.TheoryOfSet.Alphabet;

import java.util.ArrayList;

/**
* Created by IntelliJ IDEA.
* User: Alex
* Date: 25.03.11
* Time: 2:50
*/
public class Contents {
public Alphabet alphabet = new Alphabet();
public ArrayList<Integer> counts = new ArrayList<Integer>();

public void add(IBaseObject obj, int count) throws Exception {
if (!alphabet.isContains(obj)) {
alphabet.add(obj);
counts.add(count);
}
else {
int index = alphabet.indexOf(obj);
counts.set(index, counts.get(index) + count);
}
}

public void subElementCount(int index) throws Exception {
if (counts.size() < index) {
throw new Exception("Элемент с таким индексом отсутствует в составе");
}
counts.set(index - 1, counts.get(index - 1) - 1);
}

public int getElementCount(int index) throws Exception {
if (counts.size() < index) {
throw new Exception("Элемент с таким индексом отсутствует в составе");
}
return counts.get(index - 1);
}

public int getChainLength() {
int len = 0;
for (Integer count : counts) {
len += count;
}
return len;
}

@Override
public Contents clone() {
Contents contents = new Contents();
for (int index = 0; index < counts.size(); index++) {
try {
contents.add(alphabet.get(index), counts.get(index));
} catch (Exception e) {
System.err.print("Ошибка клонирпования состава");
}
}
return contents;
}

public int getPower() {
return alphabet.getPower();
}
}
14 changes: 14 additions & 0 deletions src/libiada/IntervalAnalysis/Buildings/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ public void addClildNodes(int len, int alphPower) {
}
}

public void addClildNodes(Contents contents) throws Exception {
if (contents.getChainLength() < 1)
return;
for (int i = 1; i <= Math.min(maxInPathFromRootToChild + 1, contents.getPower()); i++) {
if (contents.getElementCount(i) < 1)
continue;
Contents newNodeContents = contents.clone();
newNodeContents.subElementCount(i);
Node node = createNode(i);
node.addClildNodes(newNodeContents);
childNodes.add(node);
}
}

private Node createNode(int i) {
int max = Math.max(i, maxInPathFromRootToChild);
return new Node(i, max);
Expand Down
9 changes: 9 additions & 0 deletions src/libiada/IntervalAnalysis/Buildings/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public void rebuildTreeForBuildings(int len, int alphPower) {
root.addClildNodes(len, alphPower);
}

public void rebuildTreeForBuildings(Contents contents) throws Exception {
root = new Node(1, 1);
contents.subElementCount(1);
if (0 == contents.getChainLength()) {
return;
}
root.addClildNodes(contents);
}

public ArrayList<Chain> getBuildingsAsChains() throws Exception {
ArrayList<Chain> buildings = new ArrayList<Chain>();
ArrayList<String> strBuildings = root.getBuildings();
Expand Down

0 comments on commit 38d13a4

Please sign in to comment.