{"action":"created","comment":{"url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/comments/165309634","pull_request_review_id":93225356,"id":165309634,"diff_hunk":"@@ -0,0 +1,280 @@\n+#include <iostream>\n+#include <cmath>\n+#include <math.h>\n+#include <fstream>\n+#include <random>\n+\n+#include \"NoisyFunction.hpp\"\n+#include \"ConjGrad.hpp\"\n+#include \"MCIntegrator.hpp\"\n+#include \"FeedForwardNeuralNetwork.hpp\"\n+#include \"PrintUtilities.hpp\"\n+\n+\n+//1D Target Function\n+class Function1D {\n+public:\n+  //Function1D(){}\n+  virtual ~Function1D(){}\n+\n+  // Function evaluation\n+  virtual double f(const double &) = 0;\n+  //                    ^input\n+};\n+\n+// exp(-a*(x-b)^2)\n+class Gaussian: public Function1D{\n+private:\n+  double _a;\n+  double _b;\n+\n+public:\n+  Gaussian(const double &a, const double &b): Function1D(){\n+    _a = a;\n+    _b = b;\n+  }\n+\n+  double f(const double &x){\n+    return exp(-_a*pow(x-_b, 2));\n+  }\n+};\n+\n+// Quadratic distance between NN and 1D target function\n+class NNFitDistance1D: public MCIObservableFunctionInterface{\n+private:\n+  FeedForwardNeuralNetwork * _ffnn;\n+  Function1D * _ftarget;\n+public:\n+  NNFitDistance1D(FeedForwardNeuralNetwork * ffnn, Function1D * ftarget): MCIObservableFunctionInterface(1, 1) {_ffnn = ffnn; _ftarget = ftarget;}\n+protected:\n+    void observableFunction(const double * in, double * out){\n+\n+      _ffnn->setInput(1, &in[0]);\n+      _ffnn->FFPropagate();\n+      out[0] = pow(_ffnn->getOutput(1) - _ftarget->f(in[0]), 2);\n+\n+    }\n+};\n+\n+// Gradient of Quadratic distance between NN and 1D target function\n+class NNFitGradient1D: public MCIObservableFunctionInterface{\n+private:\n+  FeedForwardNeuralNetwork * _ffnn;\n+  Function1D * _ftarget;\n+public:\n+  NNFitGradient1D(FeedForwardNeuralNetwork * ffnn, Function1D * ftarget): MCIObservableFunctionInterface(1, ffnn->getNBeta()) {_ffnn = ffnn; _ftarget = ftarget;}\n+protected:\n+  void observableFunction(const double * in, double * out){\n+\n+    _ffnn->setInput(1, &in[0]);\n+    _ffnn->FFPropagate();\n+\n+    double nnout = _ffnn->getOutput(1);\n+    double fx = _ftarget->f(in[0]);\n+\n+    for(int i=0; i<_nobs; ++i){\n+        out[i] = 2.*(nnout - fx)*_ffnn->getVariationalFirstDerivative(1, i);\n+      }\n+  }\n+};\n+\n+//\n+class FitNN1D: public NoisyFunctionWithGradient{\n+private:\n+  FeedForwardNeuralNetwork * _ffnn;\n+  Function1D * _ftarget;\n+  MCI * _mcif, * _mcig;\n+  long _nmc;\n+  double _x0, _step0;\n+\n+public:\n+  FitNN1D(FeedForwardNeuralNetwork * ffnn, Function1D * ftarget, const long &nmc, double * irange): NoisyFunctionWithGradient(ffnn->getNBeta()){\n+    _ffnn = ffnn;\n+    _ftarget = ftarget;\n+    _nmc = nmc;\n+\n+    _x0 = 0.5*(irange[0] + irange[1]);\n+    _step0 = 0.1*(irange[1] - irange[0]);\n+\n+    _mcif = new MCI(1);\n+    _mcig = new MCI(1);\n+\n+    MCIObservableFunctionInterface * fobs = new NNFitDistance1D(_ffnn, _ftarget);\n+    MCIObservableFunctionInterface * gobs = new NNFitGradient1D(_ffnn, _ftarget);\n+\n+    _mcif->addObservable(fobs);\n+    _mcig->addObservable(gobs);\n+\n+    double ** intrange = new double*[1];\n+    intrange[0] = irange;\n+    _mcif->setIRange(intrange);\n+    _mcig->setIRange(intrange);\n+\n+    double targetacceptrate = 0.5;\n+    _mcif->setTargetAcceptanceRate(&targetacceptrate);\n+    _mcig->setTargetAcceptanceRate(&targetacceptrate);\n+\n+  }\n+","path":"examples/ex3/main.cpp","position":118,"original_position":118,"commit_id":"e1b4b8f4ea23b2f084761194dbcd966f24db368e","original_commit_id":"e1b4b8f4ea23b2f084761194dbcd966f24db368e","user":{"login":"francesco086","id":8321888,"avatar_url":"https://avatars2.githubusercontent.com/u/8321888?v=4","gravatar_id":"","url":"https://api.github.com/users/francesco086","html_url":"https://github.com/francesco086","followers_url":"https://api.github.com/users/francesco086/followers","following_url":"https://api.github.com/users/francesco086/following{/other_user}","gists_url":"https://api.github.com/users/francesco086/gists{/gist_id}","starred_url":"https://api.github.com/users/francesco086/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francesco086/subscriptions","organizations_url":"https://api.github.com/users/francesco086/orgs","repos_url":"https://api.github.com/users/francesco086/repos","events_url":"https://api.github.com/users/francesco086/events{/privacy}","received_events_url":"https://api.github.com/users/francesco086/received_events","type":"User","site_admin":false},"body":"And btw, if you don't store the pointers fobs and gobs, how are you going to delete them at the end?\r\nYou should add them to the list of private class parameters","created_at":"2018-02-01T10:14:36Z","updated_at":"2018-02-01T10:14:36Z","html_url":"https://github.com/francesco086/NoisyFunMin/pull/2#discussion_r165309634","pull_request_url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/comments/165309634"},"html":{"href":"https://github.com/francesco086/NoisyFunMin/pull/2#discussion_r165309634"},"pull_request":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2"}},"in_reply_to_id":165309102},"pull_request":{"url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2","id":166391701,"html_url":"https://github.com/francesco086/NoisyFunMin/pull/2","diff_url":"https://github.com/francesco086/NoisyFunMin/pull/2.diff","patch_url":"https://github.com/francesco086/NoisyFunMin/pull/2.patch","issue_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/2","number":2,"state":"open","locked":false,"title":"Fit NN","user":{"login":"Ithanil","id":5860369,"avatar_url":"https://avatars2.githubusercontent.com/u/5860369?v=4","gravatar_id":"","url":"https://api.github.com/users/Ithanil","html_url":"https://github.com/Ithanil","followers_url":"https://api.github.com/users/Ithanil/followers","following_url":"https://api.github.com/users/Ithanil/following{/other_user}","gists_url":"https://api.github.com/users/Ithanil/gists{/gist_id}","starred_url":"https://api.github.com/users/Ithanil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ithanil/subscriptions","organizations_url":"https://api.github.com/users/Ithanil/orgs","repos_url":"https://api.github.com/users/Ithanil/repos","events_url":"https://api.github.com/users/Ithanil/events{/privacy}","received_events_url":"https://api.github.com/users/Ithanil/received_events","type":"User","site_admin":false},"body":"Added example of NN fitting. For details see Trello. Code is finished, but still missing acceptance criteria: (Saved files), plot, short doc.","created_at":"2018-01-31T22:16:33Z","updated_at":"2018-02-01T10:14:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f30fc1bafd4e253a9d996b4a177bc34460ae700","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2/commits","review_comments_url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2/comments","review_comment_url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/2/comments","statuses_url":"https://api.github.com/repos/francesco086/NoisyFunMin/statuses/e1b4b8f4ea23b2f084761194dbcd966f24db368e","head":{"label":"francesco086:fitNN","ref":"fitNN","sha":"e1b4b8f4ea23b2f084761194dbcd966f24db368e","user":{"login":"francesco086","id":8321888,"avatar_url":"https://avatars2.githubusercontent.com/u/8321888?v=4","gravatar_id":"","url":"https://api.github.com/users/francesco086","html_url":"https://github.com/francesco086","followers_url":"https://api.github.com/users/francesco086/followers","following_url":"https://api.github.com/users/francesco086/following{/other_user}","gists_url":"https://api.github.com/users/francesco086/gists{/gist_id}","starred_url":"https://api.github.com/users/francesco086/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francesco086/subscriptions","organizations_url":"https://api.github.com/users/francesco086/orgs","repos_url":"https://api.github.com/users/francesco086/repos","events_url":"https://api.github.com/users/francesco086/events{/privacy}","received_events_url":"https://api.github.com/users/francesco086/received_events","type":"User","site_admin":false},"repo":{"id":49562368,"name":"NoisyFunMin","full_name":"francesco086/NoisyFunMin","owner":{"login":"francesco086","id":8321888,"avatar_url":"https://avatars2.githubusercontent.com/u/8321888?v=4","gravatar_id":"","url":"https://api.github.com/users/francesco086","html_url":"https://github.com/francesco086","followers_url":"https://api.github.com/users/francesco086/followers","following_url":"https://api.github.com/users/francesco086/following{/other_user}","gists_url":"https://api.github.com/users/francesco086/gists{/gist_id}","starred_url":"https://api.github.com/users/francesco086/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francesco086/subscriptions","organizations_url":"https://api.github.com/users/francesco086/orgs","repos_url":"https://api.github.com/users/francesco086/repos","events_url":"https://api.github.com/users/francesco086/events{/privacy}","received_events_url":"https://api.github.com/users/francesco086/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/francesco086/NoisyFunMin","description":"Minimisation C++ library for noisy functions","fork":false,"url":"https://api.github.com/repos/francesco086/NoisyFunMin","forks_url":"https://api.github.com/repos/francesco086/NoisyFunMin/forks","keys_url":"https://api.github.com/repos/francesco086/NoisyFunMin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/francesco086/NoisyFunMin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/francesco086/NoisyFunMin/teams","hooks_url":"https://api.github.com/repos/francesco086/NoisyFunMin/hooks","issue_events_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/events{/number}","events_url":"https://api.github.com/repos/francesco086/NoisyFunMin/events","assignees_url":"https://api.github.com/repos/francesco086/NoisyFunMin/assignees{/user}","branches_url":"https://api.github.com/repos/francesco086/NoisyFunMin/branches{/branch}","tags_url":"https://api.github.com/repos/francesco086/NoisyFunMin/tags","blobs_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/refs{/sha}","trees_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/francesco086/NoisyFunMin/statuses/{sha}","languages_url":"https://api.github.com/repos/francesco086/NoisyFunMin/languages","stargazers_url":"https://api.github.com/repos/francesco086/NoisyFunMin/stargazers","contributors_url":"https://api.github.com/repos/francesco086/NoisyFunMin/contributors","subscribers_url":"https://api.github.com/repos/francesco086/NoisyFunMin/subscribers","subscription_url":"https://api.github.com/repos/francesco086/NoisyFunMin/subscription","commits_url":"https://api.github.com/repos/francesco086/NoisyFunMin/commits{/sha}","git_commits_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/commits{/sha}","comments_url":"https://api.github.com/repos/francesco086/NoisyFunMin/comments{/number}","issue_comment_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/comments{/number}","contents_url":"https://api.github.com/repos/francesco086/NoisyFunMin/contents/{+path}","compare_url":"https://api.github.com/repos/francesco086/NoisyFunMin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/francesco086/NoisyFunMin/merges","archive_url":"https://api.github.com/repos/francesco086/NoisyFunMin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/francesco086/NoisyFunMin/downloads","issues_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues{/number}","pulls_url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls{/number}","milestones_url":"https://api.github.com/repos/francesco086/NoisyFunMin/milestones{/number}","notifications_url":"https://api.github.com/repos/francesco086/NoisyFunMin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/francesco086/NoisyFunMin/labels{/name}","releases_url":"https://api.github.com/repos/francesco086/NoisyFunMin/releases{/id}","deployments_url":"https://api.github.com/repos/francesco086/NoisyFunMin/deployments","created_at":"2016-01-13T09:07:18Z","updated_at":"2018-01-16T11:35:12Z","pushed_at":"2018-01-31T22:16:33Z","git_url":"git://github.com/francesco086/NoisyFunMin.git","ssh_url":"git@github.com:francesco086/NoisyFunMin.git","clone_url":"https://github.com/francesco086/NoisyFunMin.git","svn_url":"https://github.com/francesco086/NoisyFunMin","homepage":"","size":909,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"francesco086:master","ref":"master","sha":"aeefa2ac6a1fd8575747a506cca01a8024762654","user":{"login":"francesco086","id":8321888,"avatar_url":"https://avatars2.githubusercontent.com/u/8321888?v=4","gravatar_id":"","url":"https://api.github.com/users/francesco086","html_url":"https://github.com/francesco086","followers_url":"https://api.github.com/users/francesco086/followers","following_url":"https://api.github.com/users/francesco086/following{/other_user}","gists_url":"https://api.github.com/users/francesco086/gists{/gist_id}","starred_url":"https://api.github.com/users/francesco086/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francesco086/subscriptions","organizations_url":"https://api.github.com/users/francesco086/orgs","repos_url":"https://api.github.com/users/francesco086/repos","events_url":"https://api.github.com/users/francesco086/events{/privacy}","received_events_url":"https://api.github.com/users/francesco086/received_events","type":"User","site_admin":false},"repo":{"id":49562368,"name":"NoisyFunMin","full_name":"francesco086/NoisyFunMin","owner":{"login":"francesco086","id":8321888,"avatar_url":"https://avatars2.githubusercontent.com/u/8321888?v=4","gravatar_id":"","url":"https://api.github.com/users/francesco086","html_url":"https://github.com/francesco086","followers_url":"https://api.github.com/users/francesco086/followers","following_url":"https://api.github.com/users/francesco086/following{/other_user}","gists_url":"https://api.github.com/users/francesco086/gists{/gist_id}","starred_url":"https://api.github.com/users/francesco086/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francesco086/subscriptions","organizations_url":"https://api.github.com/users/francesco086/orgs","repos_url":"https://api.github.com/users/francesco086/repos","events_url":"https://api.github.com/users/francesco086/events{/privacy}","received_events_url":"https://api.github.com/users/francesco086/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/francesco086/NoisyFunMin","description":"Minimisation C++ library for noisy functions","fork":false,"url":"https://api.github.com/repos/francesco086/NoisyFunMin","forks_url":"https://api.github.com/repos/francesco086/NoisyFunMin/forks","keys_url":"https://api.github.com/repos/francesco086/NoisyFunMin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/francesco086/NoisyFunMin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/francesco086/NoisyFunMin/teams","hooks_url":"https://api.github.com/repos/francesco086/NoisyFunMin/hooks","issue_events_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/events{/number}","events_url":"https://api.github.com/repos/francesco086/NoisyFunMin/events","assignees_url":"https://api.github.com/repos/francesco086/NoisyFunMin/assignees{/user}","branches_url":"https://api.github.com/repos/francesco086/NoisyFunMin/branches{/branch}","tags_url":"https://api.github.com/repos/francesco086/NoisyFunMin/tags","blobs_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/refs{/sha}","trees_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/francesco086/NoisyFunMin/statuses/{sha}","languages_url":"https://api.github.com/repos/francesco086/NoisyFunMin/languages","stargazers_url":"https://api.github.com/repos/francesco086/NoisyFunMin/stargazers","contributors_url":"https://api.github.com/repos/francesco086/NoisyFunMin/contributors","subscribers_url":"https://api.github.com/repos/francesco086/NoisyFunMin/subscribers","subscription_url":"https://api.github.com/repos/francesco086/NoisyFunMin/subscription","commits_url":"https://api.github.com/repos/francesco086/NoisyFunMin/commits{/sha}","git_commits_url":"https://api.github.com/repos/francesco086/NoisyFunMin/git/commits{/sha}","comments_url":"https://api.github.com/repos/francesco086/NoisyFunMin/comments{/number}","issue_comment_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/comments{/number}","contents_url":"https://api.github.com/repos/francesco086/NoisyFunMin/contents/{+path}","compare_url":"https://api.github.com/repos/francesco086/NoisyFunMin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/francesco086/NoisyFunMin/merges","archive_url":"https://api.github.com/repos/francesco086/NoisyFunMin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/francesco086/NoisyFunMin/downloads","issues_url":"https://api.github.com/repos/francesco086/NoisyFunMin/issues{/number}","pulls_url":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls{/number}","milestones_url":"https://api.github.com/repos/francesco086/NoisyFunMin/milestones{/number}","notifications_url":"https://api.github.com/repos/francesco086/NoisyFunMin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/francesco086/NoisyFunMin/labels{/name}","releases_url":"https://api.github.com/repos/francesco086/NoisyFunMin/releases{/id}","deployments_url":"https://api.github.com/repos/francesco086/NoisyFunMin/deployments","created_at":"2016-01-13T09:07:18Z","updated_at":"2018-01-16T11:35:12Z","pushed_at":"2018-01-31T22:16:33Z","git_url":"git://github.com/francesco086/NoisyFunMin.git","ssh_url":"git@github.com:francesco086/NoisyFunMin.git","clone_url":"https://github.com/francesco086/NoisyFunMin.git","svn_url":"https://github.com/francesco086/NoisyFunMin","homepage":"","size":909,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2"},"html":{"href":"https://github.com/francesco086/NoisyFunMin/pull/2"},"issue":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/2"},"comments":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/francesco086/NoisyFunMin/statuses/e1b4b8f4ea23b2f084761194dbcd966f24db368e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"francesco086"}}