diff options
| author | ziejd2 | 2021-02-24 15:19:03 -0600 |
|---|---|---|
| committer | ziejd2 | 2021-02-24 15:19:03 -0600 |
| commit | 1427e9bf4f85823164b4573a3bcf1ba3ba6b04d0 (patch) | |
| tree | d4356879a9b0a3d44063a6b292ef0197173697af /sourcecodes/parameter_learning | |
| parent | a2b306b10fb07f07c63235861ccfe460153e8609 (diff) | |
| download | BNW-1427e9bf4f85823164b4573a3bcf1ba3ba6b04d0.tar.gz | |
Moving final GENENET8 version to master
Diffstat (limited to 'sourcecodes/parameter_learning')
| -rw-r--r-- | sourcecodes/parameter_learning/createJSON.m | 5 | ||||
| -rw-r--r-- | sourcecodes/parameter_learning/createSVG.m | 9 | ||||
| -rw-r--r-- | sourcecodes/parameter_learning/kfoldCrossValid.m | 2 | ||||
| -rw-r--r-- | sourcecodes/parameter_learning/modifyEdges.m | 15 | ||||
| -rw-r--r-- | sourcecodes/parameter_learning/normpdf.m | 50 | ||||
| -rw-r--r-- | sourcecodes/parameter_learning/normrnd.m | 130 |
6 files changed, 10 insertions, 201 deletions
diff --git a/sourcecodes/parameter_learning/createJSON.m b/sourcecodes/parameter_learning/createJSON.m index e6fd7ea2..59a3aec4 100644 --- a/sourcecodes/parameter_learning/createJSON.m +++ b/sourcecodes/parameter_learning/createJSON.m @@ -12,10 +12,6 @@ function [ ] = createJSON( pre ) % -nnodefile=strcat(pre,'nnode.txt'); -fnnode = fopen(nnodefile,'r'); -nnodes = fscanf(fnnode,'%d'); - % open file for input, include error handling dfile=strcat(pre,'structure_input.txt'); @@ -26,6 +22,7 @@ end % Read in first line to get the number of nodes and the node labels. buffer = strtrim(fgetl(fin)); %get header line as a string +nnodes = numel(strfind(buffer,"\t"))+1; labels = cell(1,nnodes); for j=1:nnodes [next,buffer] = strtok(buffer); diff --git a/sourcecodes/parameter_learning/createSVG.m b/sourcecodes/parameter_learning/createSVG.m index 2d190b68..47894c1b 100644 --- a/sourcecodes/parameter_learning/createSVG.m +++ b/sourcecodes/parameter_learning/createSVG.m @@ -16,10 +16,6 @@ function [ ] = createSVG( pre ) % -nnodefile=strcat(pre,'nnode.txt'); -fnnode = fopen(nnodefile,'r'); -nnodes = fscanf(fnnode,'%d'); - % open file for input, include error handling dfile=strcat(pre,'structure_input.txt'); @@ -30,20 +26,19 @@ end % Read in first line to get the number of nodes and the node labels. buffer = fgetl(fin); %get header line as a string - +nnodes = numel(strfind(buffer,"\t")) + 1; labels = cell(1,nnodes); for j=1:nnodes - j, buffer [next,buffer] = strtok(buffer); labels{j} = next; end + % Read in the edges edges = cell(nnodes,nnodes); for i = 1:nnodes buffer = fgetl(fin); for j = 1:nnodes - i, j, buffer [next,buffer] = strtok(buffer); edges{i,j} = next; end diff --git a/sourcecodes/parameter_learning/kfoldCrossValid.m b/sourcecodes/parameter_learning/kfoldCrossValid.m index 40b72c61..2af690d7 100644 --- a/sourcecodes/parameter_learning/kfoldCrossValid.m +++ b/sourcecodes/parameter_learning/kfoldCrossValid.m @@ -4,7 +4,7 @@ function kfoldCrossValid(pre,predict_label,nfolds) % that you want to predict and the number of folds that the % data should be divided into. -nfolds = uint8(str2num(nfolds)); +nfolds = uint16(str2num(nfolds)); sfile=strcat(pre,'structure_input.txt'); dfile=strcat(pre,'continuous_input.txt'); diff --git a/sourcecodes/parameter_learning/modifyEdges.m b/sourcecodes/parameter_learning/modifyEdges.m index 6542d9fb..c435806a 100644 --- a/sourcecodes/parameter_learning/modifyEdges.m +++ b/sourcecodes/parameter_learning/modifyEdges.m @@ -58,7 +58,6 @@ for j=1:nedges sources{j} = str2num(next); end - buffer = fgetl(fin2); buffer = buffer(2:end-1); buffer = strrep(buffer,"\"",""); @@ -76,7 +75,6 @@ for j=1:nedges weights{j} = next; end - %label_map is the index in "labels" that corresponds to each label in "labels2" label_map = cell(1,nnodes); for i = 1:nnodes @@ -99,6 +97,8 @@ for i = 1:nedges edges_out(source_i,target_i) = "1"; end +%scores_out + tf = cellfun('isempty',edges_out); edges_out(tf) = {"0"}; @@ -113,28 +113,25 @@ for i=1:nnodes end end - if test_score == 1 outfile = strcat(pre_new,'structure_input_temp.txt'); fout = fopen(outfile,'w'); fprintf(fout,'%s\t',labels{1:end-1}); -fprintf(fout,'%s\t\n',labels{end}); +fprintf(fout,'%s\n',labels{end}); for i = 1:nnodes fprintf(fout,'%s\t',scores_out{i,1:end-1}); - fprintf(fout,'%s\t\n',scores_out{i,end}); + fprintf(fout,'%s\n',scores_out{i,end}); end fclose(fout); end - - outfile2 = strcat(pre_new,'structure_input.txt'); fout2 = fopen(outfile2,'w'); fprintf(fout2,'%s\t',labels{1:end-1}); -fprintf(fout2,'%s\t\n',labels{end}); +fprintf(fout2,'%s\n',labels{end}); for i = 1:nnodes fprintf(fout2,'%s\t',edges_out{i,1:end-1}); - fprintf(fout2,'%s\t\n',edges_out{i,end}); + fprintf(fout2,'%s\n',edges_out{i,end}); end fclose(fout2); diff --git a/sourcecodes/parameter_learning/normpdf.m b/sourcecodes/parameter_learning/normpdf.m deleted file mode 100644 index 2b154f02..00000000 --- a/sourcecodes/parameter_learning/normpdf.m +++ /dev/null @@ -1,50 +0,0 @@ -function p = normpdf(x,m,s); -% Normal probability density function -% -% pdf = normpdf(x,m,s); -% -% Computes the PDF of a the normal distribution -% with mean m and standard deviation s -% default: m=0; s=1; -% x,m,s must be matrices of same size, or any one can be a scalar. -% -% see also: NORMCDF, NORMINV - -% Reference(s): - -% Version 1.28 Date: 23.Sep.2002 -% Copyright (c) 2000-2002 by Alois Schloegl <a.schloegl@ieee.org> - -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; if not, write to the Free Software -% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -if nargin==1, - m=0;s=1; -elseif nargin==2, - s=1; -end; - -% allocate output memory and check size of argument -z = (x-m)./s; % if this line causes an error, input arguments do not fit. - -%p = ((2*pi)^(-1/2))*exp(-z.^2/2)./s; -SQ2PI = 2.5066282746310005024157652848110; -p = exp(-z.^2/2)./(s*SQ2PI); - -p((x==m) & (s==0)) = inf; - -p(isinf(z)~=0) = 0; - -p(isnan(x) | isnan(m) | isnan(s) | (s<0)) = nan; - diff --git a/sourcecodes/parameter_learning/normrnd.m b/sourcecodes/parameter_learning/normrnd.m deleted file mode 100644 index 0267ddf6..00000000 --- a/sourcecodes/parameter_learning/normrnd.m +++ /dev/null @@ -1,130 +0,0 @@ -## Copyright (C) 2012 Rik Wehbring -## Copyright (C) 1995-2012 Kurt Hornik -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} normrnd (@var{mu}, @var{sigma}) -## @deftypefnx {Function File} {} normrnd (@var{mu}, @var{sigma}, @var{r}) -## @deftypefnx {Function File} {} normrnd (@var{mu}, @var{sigma}, @var{r}, @var{c}, @dots{}) -## @deftypefnx {Function File} {} normrnd (@var{mu}, @var{sigma}, [@var{sz}]) -## Return a matrix of random samples from the normal distribution with -## parameters mean @var{mu} and standard deviation @var{sigma}. -## -## When called with a single size argument, return a square matrix with -## the dimension specified. When called with more than one scalar argument the -## first two arguments are taken as the number of rows and columns and any -## further arguments specify additional matrix dimensions. The size may also -## be specified with a vector of dimensions @var{sz}. -## -## If no size arguments are given then the result matrix is the common size of -## @var{mu} and @var{sigma}. -## @end deftypefn - -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: Random deviates from the normal distribution - -function rnd = normrnd (mu, sigma, varargin) - - if (nargin < 2) - print_usage (); - endif - - if (!isscalar (mu) || !isscalar (sigma)) - [retval, mu, sigma] = common_size (mu, sigma); - if (retval > 0) - error ("normrnd: mu and sigma must be of common size or scalars"); - endif - endif - - if (iscomplex (mu) || iscomplex (sigma)) - error ("normrnd: MU and SIGMA must not be complex"); - endif - - if (nargin == 2) - sz = size (mu); - elseif (nargin == 3) - if (isscalar (varargin{1}) && varargin{1} >= 0) - sz = [varargin{1}, varargin{1}]; - elseif (isrow (varargin{1}) && all (varargin{1} >= 0)) - sz = varargin{1}; - else - error ("normrnd: dimension vector must be row vector of non-negative integers"); - endif - elseif (nargin > 3) - if (any (cellfun (@(x) (!isscalar (x) || x < 0), varargin))) - error ("normrnd: dimensions must be non-negative integers"); - endif - sz = [varargin{:}]; - endif - - if (!isscalar (mu) && !isequal (size (mu), sz)) - error ("normrnd: mu and sigma must be scalar or of size SZ"); - endif - - if (isa (mu, "single") || isa (sigma, "single")) - cls = "single"; - else - cls = "double"; - endif - - if (isscalar (mu) && isscalar (sigma)) - if (!isnan (mu) && !isinf (mu) && (sigma > 0) && (sigma < Inf)) - rnd = mu + sigma * randn (sz); - else - rnd = NaN (sz, cls); - endif - else - rnd = mu + sigma .* randn (sz); - k = isnan (mu) | isinf (mu) | !(sigma > 0) | !(sigma < Inf); - rnd(k) = NaN; - endif - -endfunction - - -%!assert(size (normrnd (1,2)), [1, 1]); -%!assert(size (normrnd (ones(2,1), 2)), [2, 1]); -%!assert(size (normrnd (ones(2,2), 2)), [2, 2]); -%!assert(size (normrnd (1, 2*ones(2,1))), [2, 1]); -%!assert(size (normrnd (1, 2*ones(2,2))), [2, 2]); -%!assert(size (normrnd (1, 2, 3)), [3, 3]); -%!assert(size (normrnd (1, 2, [4 1])), [4, 1]); -%!assert(size (normrnd (1, 2, 4, 1)), [4, 1]); - -%% Test class of input preserved -%!assert(class (normrnd (1, 2)), "double"); -%!assert(class (normrnd (single(1), 2)), "single"); -%!assert(class (normrnd (single([1 1]), 2)), "single"); -%!assert(class (normrnd (1, single(2))), "single"); -%!assert(class (normrnd (1, single([2 2]))), "single"); - -%% Test input validation -%!error normrnd () -%!error normrnd (1) -%!error normrnd (ones(3),ones(2)) -%!error normrnd (ones(2),ones(3)) -%!error normrnd (i, 2) -%!error normrnd (2, i) -%!error normrnd (1,2, -1) -%!error normrnd (1,2, ones(2)) -%!error normrnd (1, 2, [2 -1 2]) -%!error normrnd (1,2, 1, ones(2)) -%!error normrnd (1,2, 1, -1) -%!error normrnd (ones(2,2), 2, 3) -%!error normrnd (ones(2,2), 2, [3, 2]) -%!error normrnd (ones(2,2), 2, 2, 3) |
