ID3 アルゴリズムの簡易版である非バイナリ学習ツリーを作成しようとしています。これを行うために、列挙型階層を教えている参照がいくつかあるため、列挙型を使用しようとしましたが、ツリーを作成するために必要な関数への列挙型の転送に問題があります。ツリーに必要なすべてをできる限りセットアップしましたが、ツリーの初期構築に問題があります。
まず、「main.enumname」をあちこちに記述する必要がないように、それぞれ独自のファイルを持つ 6 つの列挙型を作成しました。これらの最初の 5 つの列挙型は、車の診断を表します。
public enum fuelstats {notempty, empty}
public enum lightstatus {Dim, Normal}
public enum scents {normal, gas}
public enum soundstatus {Normal, Howl, Screech, Click}
public enum turn {no, yes}
次に、さらに 2 つの列挙型を作成しました。1 つはさまざまな診断結果用で、もう 1 つは車の診断のさまざまな「トピック」用です。
public enum problems {battery, starter, solenoid, outofgas, flooding}
public enum features {lightstatus, soundstatus, fuelstats, scents, turn, problems}
次に、さまざまな車の診断の 5 つのデータ例を作成し、ツリーで並べ替えました。
Example example1 = new Example(lightstatus.Dim, soundstatus.Howl, turn.yes, fuelstats.notempty, scents.normal, problems.battery);
Example example2 = new Example(lightstatus.Normal, soundstatus.Screech, turn.no, fuelstats.notempty, scents.normal, problems.starter);
Example example3 = new Example(lightstatus.Normal, soundstatus.Click, turn.no, fuelstats.notempty, scents.normal, problems.solenoid);
Example example4 = new Example(lightstatus.Normal, soundstatus.Normal, turn.yes, fuelstats.empty, scents.normal, problems.outofgas);
Example example5 = new Example(lightstatus.Normal, soundstatus.Normal, turn.yes, fuelstats.notempty, scents.gas, problems.flooding);
//make an array list of Examples.
ArrayList<Example> Examples = new ArrayList<Example>();
Examples.add(example1);
Examples.add(example2);
Examples.add(example3);
Examples.add(example4);
Examples.add(example5);
シャッフルの目的で、Features と呼ばれるさまざまな車の診断を ArrayList に入れます。これは、これらがツリーを構築するためにランダムに使用されるためです。
//This ArrayList holds the Enums for shuffling purposes.
ArrayList<features> Features = new ArrayList<features>();
Features.add(features.soundstatus);
Features.add(features.lightstatus);
Features.add(features.turn);
Features.add(features.scents);
Features.add(features.fuelstats);
// Shuffle the elements in the list
Collections.shuffle(Features);
//The Features Array List is now a shuffled tree.
//We will do a single loop that will serve as our stack.
//First we take the top of the list and assign it to the root.
Tree id3 = new Tree(Features.get(0),Examples);
しかし、次のようなツリーを作成するにはどうすればよいですか? ルートのサブジェクトを列挙型に一致させ、列挙型のさまざまなステータスすべてを子にする機能列挙型を取得しますか? たとえば、soundstatus がルートの場合、Normal、Howl、Screech、Click の 4 つの子を作成する必要があります。そうすれば、例の音と子供の音を一致させることができます。これはこれまでの私のノードです。
public class Node
{
ArrayList<Node> children;
/* Constructor*/
public Node(ArrayList<Node> ExampleList)
{
this.ExampleList = ExampleList;
this.parent = parent;
this.children = children;
}
public ArrayList<Node> getChildren()
{
return children;
}
public void addChild(Node n)
{
children.add(n);
}
private ArrayList<Node> children;
Enum phrase;
private boolean isUsed;
Node parent;
public void setUsed(boolean isUsed)
{
this.isUsed = isUsed;
}
public boolean isUsed()
{
return isUsed;
}
//This method states if the node is a leaf
public boolean isLeaf()
{
if (this.getChildren() == null)
return true;
else
return false;
}
}