optimization

Function tabulation and wrapping

百般思念 提交于 2021-02-11 09:11:44
问题 I'm doing [very] intense numerical calculations related to physics using solvers written in C++. A single run can take up to few hours on my PC, and one need dozens. I've found that it is possible to significantly (2-5x) decrease the time almost without losing accuracy, if one tabulates smooth functions and uses tabulated values instead. The code below illustrates what do I mean: main.h #pragma once #include <iostream> #include <chrono> #include <math.h> #include <memory> typedef double(*fnc)

Function tabulation and wrapping

China☆狼群 提交于 2021-02-11 09:11:37
问题 I'm doing [very] intense numerical calculations related to physics using solvers written in C++. A single run can take up to few hours on my PC, and one need dozens. I've found that it is possible to significantly (2-5x) decrease the time almost without losing accuracy, if one tabulates smooth functions and uses tabulated values instead. The code below illustrates what do I mean: main.h #pragma once #include <iostream> #include <chrono> #include <math.h> #include <memory> typedef double(*fnc)

Function tabulation and wrapping

自作多情 提交于 2021-02-11 09:07:57
问题 I'm doing [very] intense numerical calculations related to physics using solvers written in C++. A single run can take up to few hours on my PC, and one need dozens. I've found that it is possible to significantly (2-5x) decrease the time almost without losing accuracy, if one tabulates smooth functions and uses tabulated values instead. The code below illustrates what do I mean: main.h #pragma once #include <iostream> #include <chrono> #include <math.h> #include <memory> typedef double(*fnc)

Function tabulation and wrapping

戏子无情 提交于 2021-02-11 09:07:34
问题 I'm doing [very] intense numerical calculations related to physics using solvers written in C++. A single run can take up to few hours on my PC, and one need dozens. I've found that it is possible to significantly (2-5x) decrease the time almost without losing accuracy, if one tabulates smooth functions and uses tabulated values instead. The code below illustrates what do I mean: main.h #pragma once #include <iostream> #include <chrono> #include <math.h> #include <memory> typedef double(*fnc)

Make sums of left and right sides of array equal by removing subarray

纵然是瞬间 提交于 2021-02-10 22:14:00
问题 C program that finds starting and ending indexes of subarray to remove to make given array have equal sums of left and right side. If its impossible print -1. I need it to work for any array, this is just for testing. Heres a code that finds equilibrium. #include <stdio.h> int equilibrium(int arr[], int n) { int i, j; int leftsum, rightsum; /* Check for indexes one by one until an equilibrium index is found */ for (i = 0; i < n; ++i) { /* get left sum */ leftsum = 0; for (j = 0; j < i; j++)

lmfit model fitting and then prediction

孤街浪徒 提交于 2021-02-10 21:54:19
问题 I was adopting lmfit to do a curve fitting and use that fitted model to do prediction. However, the following code did not achieve what I want. Could you please help? Thanks. import numpy as np from lmfit import Model def linearModel(x, a0, a1): return a0+a1*x #main code begin here X=[1,2,4] # data for fitting y=[2,4,6] # data for fitting gmodel = Model(linearModel) #select model params = gmodel.make_params(a0=1, a1=1) # initial params result = gmodel.fit(y, params, x=X) # curve fitting x1=[1

lmfit model fitting and then prediction

你。 提交于 2021-02-10 21:52:12
问题 I was adopting lmfit to do a curve fitting and use that fitted model to do prediction. However, the following code did not achieve what I want. Could you please help? Thanks. import numpy as np from lmfit import Model def linearModel(x, a0, a1): return a0+a1*x #main code begin here X=[1,2,4] # data for fitting y=[2,4,6] # data for fitting gmodel = Model(linearModel) #select model params = gmodel.make_params(a0=1, a1=1) # initial params result = gmodel.fit(y, params, x=X) # curve fitting x1=[1

Add blocks of values to a tensor at specific locations in PyTorch

心不动则不痛 提交于 2021-02-10 14:42:03
问题 I have a list of indices: indx = torch.LongTensor([ [ 0, 2, 0], [ 0, 2, 4], [ 0, 4, 0], [ 0, 10, 14], [ 1, 4, 0], [ 1, 8, 2], [ 1, 12, 0] ]) And I have a tensor of 2x2 blocks: blocks = torch.FloatTensor([ [[1.5818, 2.3108], [2.6742, 3.0024]], [[2.0472, 1.6651], [3.2807, 2.7413]], [[1.5587, 2.1905], [1.9231, 3.5083]], [[1.6007, 2.1426], [2.4802, 3.0610]], [[1.9087, 2.1021], [2.7781, 3.2282]], [[1.5127, 2.6322], [2.4233, 3.6836]], [[1.9645, 2.3831], [2.8675, 3.3770]] ]) What I want to do is to

Add blocks of values to a tensor at specific locations in PyTorch

依然范特西╮ 提交于 2021-02-10 14:38:43
问题 I have a list of indices: indx = torch.LongTensor([ [ 0, 2, 0], [ 0, 2, 4], [ 0, 4, 0], [ 0, 10, 14], [ 1, 4, 0], [ 1, 8, 2], [ 1, 12, 0] ]) And I have a tensor of 2x2 blocks: blocks = torch.FloatTensor([ [[1.5818, 2.3108], [2.6742, 3.0024]], [[2.0472, 1.6651], [3.2807, 2.7413]], [[1.5587, 2.1905], [1.9231, 3.5083]], [[1.6007, 2.1426], [2.4802, 3.0610]], [[1.9087, 2.1021], [2.7781, 3.2282]], [[1.5127, 2.6322], [2.4233, 3.6836]], [[1.9645, 2.3831], [2.8675, 3.3770]] ]) What I want to do is to

Multi-class Logistic Regression from scratch

这一生的挚爱 提交于 2021-02-10 14:18:14
问题 I am trying to implement from scratch the multiclass logistic regression but my implementation returns bad results. I believe the definition of the gradient function and the cost function is fine. Maybe there is a problem with how these functions are interacting with the minimize function. I have tried it but I could not find out what is wrong. Could you please cast some light? You can add the estimator 'myLR': myLR(**par_dict), with paramters par_dict= {'alpha': 0.1, 'maxit': 2000, 'opt