MilesCranmer commited on
Commit
fee23e7
·
1 Parent(s): 7f6d86d

Simplify try catch

Browse files
Files changed (1) hide show
  1. julia/sr.jl +23 -23
julia/sr.jl CHANGED
@@ -316,14 +316,8 @@ end
316
 
317
  # Score an equation
318
  function scoreFunc(tree::Node)::Float32
319
- try
320
- prediction = evalTreeArray(tree)
321
- if weighted
322
- mse = MSE(prediction, y, weights)
323
- else
324
- mse = MSE(prediction, y)
325
- end
326
- return mse / baselineMSE + countNodes(tree)*parsimony
327
  catch error
328
  if isa(error, DomainError) || isa(error, LoadError) || isa(error, TaskFailedException)
329
  return 1f9
@@ -331,25 +325,21 @@ function scoreFunc(tree::Node)::Float32
331
  throw(error)
332
  end
333
  end
 
 
 
 
 
 
334
  end
335
 
336
  # Score an equation with a small batch
337
  function scoreFuncBatch(tree::Node)::Float32
338
- try
339
- # batchSize
340
- batch_idx = randperm(len)[1:batchSize]
341
- batch_X = X[batch_idx, :]
342
- batch_y = y[batch_idx]
343
- prediction = evalTreeArray(tree, batch_X)
344
- size_adjustment = 1
345
- if weighted
346
- batch_w = weights[batch_idx]
347
- mse = MSE(prediction, batch_y, batch_w)
348
- size_adjustment = 1f0 * len / batchSize
349
- else
350
- mse = MSE(prediction, batch_y)
351
- end
352
- return size_adjustment * mse / baselineMSE + countNodes(tree)*parsimony
353
  catch error
354
  if isa(error, DomainError) || isa(error, LoadError) || isa(error, TaskFailedException)
355
  return 1f9
@@ -357,6 +347,16 @@ function scoreFuncBatch(tree::Node)::Float32
357
  throw(error)
358
  end
359
  end
 
 
 
 
 
 
 
 
 
 
360
  end
361
 
362
  # Add a random unary/binary operation to the end of a tree
 
316
 
317
  # Score an equation
318
  function scoreFunc(tree::Node)::Float32
319
+ prediction = try
320
+ evalTreeArray(tree)
 
 
 
 
 
 
321
  catch error
322
  if isa(error, DomainError) || isa(error, LoadError) || isa(error, TaskFailedException)
323
  return 1f9
 
325
  throw(error)
326
  end
327
  end
328
+ if weighted
329
+ mse = MSE(prediction, y, weights)
330
+ else
331
+ mse = MSE(prediction, y)
332
+ end
333
+ return mse / baselineMSE + countNodes(tree)*parsimony
334
  end
335
 
336
  # Score an equation with a small batch
337
  function scoreFuncBatch(tree::Node)::Float32
338
+ # batchSize
339
+ batch_idx = randperm(len)[1:batchSize]
340
+ batch_X = X[batch_idx, :]
341
+ prediction = try
342
+ evalTreeArray(tree, batch_X)
 
 
 
 
 
 
 
 
 
 
343
  catch error
344
  if isa(error, DomainError) || isa(error, LoadError) || isa(error, TaskFailedException)
345
  return 1f9
 
347
  throw(error)
348
  end
349
  end
350
+ size_adjustment = 1f0
351
+ batch_y = y[batch_idx]
352
+ if weighted
353
+ batch_w = weights[batch_idx]
354
+ mse = MSE(prediction, batch_y, batch_w)
355
+ size_adjustment = 1f0 * len / batchSize
356
+ else
357
+ mse = MSE(prediction, batch_y)
358
+ end
359
+ return size_adjustment * mse / baselineMSE + countNodes(tree)*parsimony
360
  end
361
 
362
  # Add a random unary/binary operation to the end of a tree