2017-10-29 23 views
-1

このニューラルネットワークは、インターフェイスを不和ボットとして構築しています。それはhttps://discord.gg/N5Bke3zで見つけることができます。 resetコマンドは、learnコマンドの前に完了していれば完全に動作します。 learnコマンドは、メッセージリスナー内では応答しません。カバレッジを確認した後、if elseステートメントのようには不可能なものをスキップしていることに気付きました。私が使用している2つのapiは、javacord https://github.com/BtoBastian/Javacordと、データを処理するための私の個人用api https://github.com/NicksWorld/Networking-DataTypesです。私のコードでは不一致のボットトークンが失われていますが、トークンは問題ではないことを保証します。コンソールログはjavacordからの起動ログを除いて空です:ニューラルネットワークは、学習したことに積極的に反応していません

2017年10月29日10時33分48秒AM de.btobastian.javacord.utils.JavacordLogger 情報INFO:いいえSLF4J互換ロガーが見つかりました。デフォルトの のjavacord実装を使用してください!

ご迷惑をおかけして申し訳ありません。私のコードはhttps://github.com/NicksWorld/Java-neural-networkにあり、次のように: Bot.java:

package Discord; 

import com.google.common.util.concurrent.FutureCallback; 

import Discord.message.Message; 
import de.btobastian.javacord.DiscordAPI; 
import de.btobastian.javacord.Javacord; 

public class Bot { 
    public static void main(String[] args) { 
     //get login info 
     DiscordAPI api = Javacord.getApi("*****************", true); 
     //login 
     api.connect(new FutureCallback<DiscordAPI>() { 
      @Override 
      public void onSuccess(final DiscordAPI api) { 
       //set game and start listener 
       api.setGame("Learning through Network001's algorithms"); 
       api.registerListener(new Message()); 
      } 

      @Override 
      public void onFailure(Throwable t) { 
       t.printStackTrace(); 
      } 
     }); 
    } 
} 

Message.java:

package Discord.message; 

import de.btobastian.javacord.DiscordAPI; 
import de.btobastian.javacord.listener.message.MessageCreateListener; 
import me.NicksWorld.obj.DataCollection; 
import me.NicksWorld.obj.IntegerRow; 

public class Message implements MessageCreateListener{ 
    Network network = new Network(); 

    public IntegerRow StringToRow(String in) { 
     String arr = in; 
     String[] items = arr.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(","); 
     IntegerRow results = new IntegerRow(items.length); 
     for (int i = 0; i < items.length; i++) { 
      try { 
       results.set(i, Integer.parseInt(items[i])); 
      } catch (NumberFormatException nfe) { 
       nfe.printStackTrace(); 
      } 
     } 
     return results; 
    } 

    @Override 
    public void onMessageCreate(DiscordAPI api, de.btobastian.javacord.entities.message.Message message) { 
     //Stop interaction from bots 
     if(message.getAuthor().isBot()) { 
      return; 
     } 

     //register help command 
     if (message.getContent().startsWith("!help")) { 
      message.reply(message.getAuthor().getMentionTag() + "\n!help - Shows this list\n!learn - learns from a dataset in the form of an array ex. [1,2,3,4,5], that array tells it that it has the numbers 1, 2, 3, and 4. It also tells it that the result should be 5\n!find - takes an input of 4 numbers in an array ex. [1,2,3,4] so it can find an output based on conjectures from the training data"); 
     } else if(message.getContent().startsWith("!learn")) { 
      if (network.learn(StringToRow(message.getContent().substring(7)))) { 
       message.reply("Succes!"); 
      } else { 
       message.reply("Fail :C"); 
      } 
     } else if(message.getContent().startsWith("!find")) { 

     } else if(message.getContent().startsWith("!reset")) { 
      network.TrainingData = new DataCollection(); 
      message.reply("done"); 
     } 
    } 
} 

Network.java:

package Discord.message; 

import me.NicksWorld.obj.DataCollection; 
import me.NicksWorld.obj.IntegerRow; 

public class Network { 
    //Initialize collection of training data 
    public DataCollection TrainingData = new DataCollection(); 
    //End initialize collection of training data 

    //Initialize result variable 
    public Double datasetResult = 0.0; 
    //End initialize result variable 

    //Initialize fails variable 
    public Integer fails = 0; 
    //End initialize fails variable 

    //Initialize done learning boolean 
    public boolean doneLearning = false; 
    //End initialize done learning boolean 

    //Initialize weights 
    //Initialize column 1's weight 
    public double ColumnWeight1 = Math.round(Math.random()); 
    //Initialize column 2's weight 
    public double ColumnWeight2 = Math.round(Math.random()); 
    //Initialize column 3's weight 
    public double ColumnWeight3 = Math.round(Math.random()); 
    //Initialize column 4's weight 
    public double ColumnWeight4 = Math.round(Math.random()); 
    //End initialize weights 


    //Function to check weights against all datasets 
    public boolean checkWeights() { 
     for (Integer indexOfTrainingData = 1; indexOfTrainingData <= TrainingData.get("integer").size(); indexOfTrainingData++) { 
      //Reset variables for data 
      datasetResult = 0.0; 
      IntegerRow rowVar = (IntegerRow)TrainingData.get("integer").get(indexOfTrainingData - 1); 
      //End reseting of variables 

      //loop through the row 
      for (Integer indexOfRow=1; indexOfRow <= 4; indexOfRow++) { 
       //Determine which weight to use per value 
       if (indexOfRow==1) { 
        datasetResult += ColumnWeight1 * rowVar.get().get(0); 
       } else if (indexOfRow == 2) { 
        datasetResult += ColumnWeight2 * rowVar.get().get(1); 
       } else if (indexOfRow == 3) { 
        datasetResult += ColumnWeight3 * rowVar.get().get(2); 
       } else if (indexOfRow == 4) { 
        datasetResult += ColumnWeight4 * rowVar.get().get(3); 
       } 
      } 
      if (datasetResult == rowVar.get().get(4).intValue()) { 

      } else { 
       return false; 
      } 
     } 
     return true; 
    } 

    //Function to learn 
    public Boolean learn(IntegerRow ToLearn) { 
     //if(ToLearn.get().size()!=4) return false; 
     //Add to training data list 
     TrainingData.add(ToLearn); 

     //loop through the training data 
     fails = 0; 
     for (Integer indexOfTrainingData = 1; indexOfTrainingData <= TrainingData.get("int").size(); indexOfTrainingData++) { 
      //Reset variables for data 
      datasetResult = 0.0; 
      IntegerRow rowVar = (IntegerRow)TrainingData.get("int").get(indexOfTrainingData - 1); 
      doneLearning = false; 
      //End reseting of variables 

      //determine when the for loop is complete 
      while (!doneLearning) { 
       //loop through the row 
       for (Integer indexOfRow = 1; indexOfRow <= 4; indexOfRow++) { 
        //Determine which weight to use per value 
        if (indexOfRow==1) { 
         datasetResult += ColumnWeight1 * rowVar.get().get(0); 
        } else if (indexOfRow == 2) { 
         datasetResult += ColumnWeight2 * rowVar.get().get(1); 
        } else if (indexOfRow == 3) { 
         datasetResult += ColumnWeight3 * rowVar.get().get(2); 
        } else if (indexOfRow == 4) { 
         datasetResult += ColumnWeight4 * rowVar.get().get(3); 
        } 
       } 
       if (datasetResult == rowVar.get().get(4).intValue()) { 
        //check if successful with other datasets 
        if(checkWeights()) { 
         return true; 
        } 
       } else { 
        fails++; 
        //Re-randomize weights 
        ColumnWeight1 = Math.round(Math.random()); 
        ColumnWeight2 = Math.round(Math.random()); 
        ColumnWeight3 = Math.round(Math.random()); 
        ColumnWeight4 = Math.round(Math.random()); 
       } 
      } 
      return false; 
     } 
     return false; 
    } 
} 

編集:私は固定されている 失敗カウントが正しいポイントでリセットされなかったことを発見することによって、エラーが発生しました。

+0

「解決済み」を含むようにタイトルを編集しないでください。 – user1803551

答えて

0

私は多くのデバッグを行い、問題を1行に正確に突き止めました。失敗カウントは、学習プロセスの終了から失敗カウントを停止した時点でリセットされていました。 Network.javaの新しいコードは次のとおりです。

package Discord.message; 

import de.btobastian.javacord.DiscordAPI; 
import de.btobastian.javacord.entities.message.Message; 
import me.NicksWorld.obj.DataCollection; 
import me.NicksWorld.obj.IntegerRow; 

public class Network { 
    //Initialize collection of training data 

    public DataCollection TrainingData = new DataCollection(); 

    //End initialize collection of training data 


    //Initialize result variable 

    public Double datasetResult = 0.0; 

    //End initialize result variable 


    //Initialize fails variable 

    public Integer fails = 0; 

    //End initialize fails variable 


    //Initialize done learning boolean 

    public boolean doneLearning = false; 

    //End initialize done learning boolean 


    //Initialize weights 

    //Initialize column 1's weight 
    public double ColumnWeight1 = Math.round(Math.random()); 
    //Initialize column 2's weight 
    public double ColumnWeight2 = Math.round(Math.random()); 
    //Initialize column 3's weight 
    public double ColumnWeight3 = Math.round(Math.random()); 
    //Initialize column 4's weight 
    public double ColumnWeight4 = Math.round(Math.random()); 

    //End initialize weights 


    //Function to check weights against all datasets 

    public boolean checkWeights() { 
     for(Integer indexOfTrainingData=1;indexOfTrainingData<=TrainingData.get("int").size();indexOfTrainingData++) { 

      //Reset variables for data 

      datasetResult = 0.0; 
      IntegerRow rowVar = (IntegerRow) TrainingData.get("int").get(indexOfTrainingData - 1); 

      //End reseting of variables 


      //loop through the row 

      for(Integer indexOfRow=1;indexOfRow<=4;indexOfRow++) { 
       //Determine which weight to use per value 
       if(indexOfRow==1) { 
        datasetResult += ColumnWeight1*rowVar.get().get(0); 
       }else if(indexOfRow==2) { 
        datasetResult += ColumnWeight2*rowVar.get().get(1); 
       }else if(indexOfRow==3) { 
        datasetResult += ColumnWeight3*rowVar.get().get(2); 
       }else if(indexOfRow==4) { 
        datasetResult += ColumnWeight4*rowVar.get().get(3); 
       } 
      } 
      if(datasetResult==rowVar.get().get(4).intValue()) { 

      }else { 
       return false; 
      } 
     } 
     return true; 
    } 


    //Function to learn 

    public Boolean learn(IntegerRow ToLearn, Message message) { 
     if(ToLearn.get().size()!=5) { 
      return false; 
     } 

     //Add to training data list 

     TrainingData.add(ToLearn); 


     //loop through the training data 
     for(Integer indexOfTrainingData=1;indexOfTrainingData<=TrainingData.get("int").size();indexOfTrainingData++) { 
      //Reset variables for data 

      datasetResult = 0.0; 
      IntegerRow rowVar = (IntegerRow) TrainingData.get("int").get(indexOfTrainingData - 1); 
      doneLearning = false; 
      //End reseting of variables 

      //determine when the for loop is complete 

      while(doneLearning != true) { 
       //loop through the row 
       datasetResult = 0.0; 
       for(Integer indexOfRow=1;indexOfRow<=4;indexOfRow++) { 
        //Determine which weight to use per value 
        if(indexOfRow==1) { 
         datasetResult += ColumnWeight1*rowVar.get().get(0); 
        }else if(indexOfRow==2) { 
         datasetResult += ColumnWeight2*rowVar.get().get(1); 
        }else if(indexOfRow==3) { 
         datasetResult += ColumnWeight3*rowVar.get().get(2); 
        }else if(indexOfRow==4) { 
         datasetResult += ColumnWeight4*rowVar.get().get(3); 
        } 
       } 
       if(datasetResult==rowVar.get().get(4).intValue()) { 
        //check if successful with other datasets 
        Boolean test = checkWeights(); 
        if(test==true) { 
         return true; 
        } 
       }else { 
        fails++; 
        if(fails>1000) { 
         TrainingData = new DataCollection(); return false; 
        } 

        if(fails == 50|fails == 100|fails == 150|fails == 200|fails == 250) message.reply("Working..."); 
        //Re-randomize weights 
        ColumnWeight1 = Math.round(Math.random()); 
        ColumnWeight2 = Math.round(Math.random()); 
        ColumnWeight3 = Math.round(Math.random()); 
        ColumnWeight4 = Math.round(Math.random()); 
       } 
      } 
      TrainingData = new DataCollection(); 
      return false; 
     } 
     TrainingData = new DataCollection(); 
     return false; 
    } 
    // 
    public Double findResult = 0.0; 
    public Double find(IntegerRow in) { 
     findResult = 0.0; 

     for(Integer indexOfRow=1;indexOfRow<=4;indexOfRow++) { 
      //Determine which weight to use per value 
      if(indexOfRow==1) { 
       findResult += ColumnWeight1*in.get().get(0); 
      }else if(indexOfRow==2) { 
       findResult += ColumnWeight2*in.get().get(1); 
      }else if(indexOfRow==3) { 
       findResult += ColumnWeight3*in.get().get(2); 
      }else if(indexOfRow==4) { 
       findResult += ColumnWeight4*in.get().get(3); 
      } 
     } 
     return findResult; 
    } 
} 
関連する問題