Diff of /inst/nls_obj.m [000000] .. [afe5a1]  Maximize  Restore

Switch to unified view

a b/inst/nls_obj.m
1
# Copyright (C) 2005  Michael Creel <michael.creel@uab.es>
2
# 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
# 
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
# 
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
# usage: [obj_value, score] = nls_obj(theta, data, model, modelargs, nslaves)
18
#
19
# Returns the average sum of squared errors for a specified model
20
# This is for internal use by nls_estimate
21
22
23
function [obj_value, score] = nls_obj(theta, data, model, modelargs, nslaves)
24
25
  n = rows(data);   
26
27
  if nslaves > 0
28
      global NEWORLD NSLAVES TAG
29
      nn = floor(n/(NSLAVES + 1)); # number of obsns per slave
30
    
31
      # The command that the slave nodes will execute
32
          cmd=['contrib = nls_obj_nodes(theta, data, model, modelargs, nn); ',... 
33
           'MPI_Send(contrib,0,TAG,NEWORLD);'];   
34
35
      # send items to slaves
36
      NumCmds_Send({"theta", "nn", "cmd"}, {theta, nn, cmd});
37
38
      # evaluate last block on master while slaves are busy
39
      obj_value = nls_obj_nodes(theta, data, model, modelargs, nn);
40
41
      # collect slaves' results
42
      contrib = 0.0; # must be initialized to use MPI_Recv
43
      for i = 1:NSLAVES
44
          MPI_Recv(contrib,i,TAG,NEWORLD);
45
          obj_value = obj_value + contrib;
46
      endfor
47
48
      # compute the average
49
          obj_value = obj_value / n;
50
          score = "na"; # fix this later to allow analytic score in parallel
51
52
  else # serial version
53
          [contribs, score] = feval(model, theta, data, modelargs);
54
      obj_value = mean(contribs);
55
          if isnumeric(score) score = mean(score)'; endif # model passes "na" when score not available
56
      endif
57
58
  # let's bullet-proof this in case the model goes nuts
59
  if (((abs(obj_value) == Inf)) || (isnan(obj_value))) obj_value = realmax; endif
60
61
endfunction

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks