How to call numpy solver to minimize a obj_func with constraints












0















I'm trying to solve a linear equation problem with constraints but I have no idea of how to call the solver.



I'm using a function that I wrote called covariancia but there's no problem with it, so I'll not post it here.



from funcs import covariancia
from math import sqrt
def main():
print("Iniciando Moneta...")
evo_val =
with open("evo_val.txt") as my_file:
evo_val = [line.split() for line in my_file]

#Montando array de Médias
medias =

for papel in evo_val:
media_atual = 0

for valor in papel:
media_atual += float(valor)

media_atual /= len(papel)
medias.append(media_atual)

#Calculating Covariance
co_x = co_y = len(evo_val)
co_var = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):

for j in range(len(evo_val)):
if (j < i):
co_var[i][j] = co_var[j][i]
else:
co_var[i][j] = covariancia(evo_val[i], evo_val[j], medias[i], medias[j])

#Calculating Correlation
co_rel = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):
for j in range(len(evo_val)):
if i == j:
co_rel[i][j] = 1
elif j < i:
co_rel[i][j] = co_rel[j][i]
else:
co_rel[i][j] = co_var[i][j] / (sqrt(co_var[i][i] * co_var[j][j]))

#Linear Solver
func_obj = [0.0 for i in range(co_x)]
DPRE = 0.0

RE = sum([func_obj[i]*medias[i] for i in range(len(evo_val))])

for i in range(co_x):
for j in range(co_x):
DPRE += func_obj[i]*func_obj[j]*co_var[i][j]

const = sum(func_obj) # must be equal to 1


What must I do? I need to minimize (DPRE/RE) with the constraints that sum(func_obj) must be equal to 1.



How can I call the solver? How can I tell the solver that my variables are in the array func_obj?



Thanks for the help!










share|improve this question

























  • Did you have a look at the documentation on NumPy minimization? This may be of help here...

    – sophros
    Nov 18 '18 at 15:27











  • @sophros Yes i did. The problem is i'm not used to work with optmizations and research problems, linear algs, etc... i don't know which func of the linalg should I use, i don't know how to tell the variables, the constraints. I didn't find and example that's close enough to my problem i guess.

    – Thomas Leick
    Nov 18 '18 at 16:32
















0















I'm trying to solve a linear equation problem with constraints but I have no idea of how to call the solver.



I'm using a function that I wrote called covariancia but there's no problem with it, so I'll not post it here.



from funcs import covariancia
from math import sqrt
def main():
print("Iniciando Moneta...")
evo_val =
with open("evo_val.txt") as my_file:
evo_val = [line.split() for line in my_file]

#Montando array de Médias
medias =

for papel in evo_val:
media_atual = 0

for valor in papel:
media_atual += float(valor)

media_atual /= len(papel)
medias.append(media_atual)

#Calculating Covariance
co_x = co_y = len(evo_val)
co_var = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):

for j in range(len(evo_val)):
if (j < i):
co_var[i][j] = co_var[j][i]
else:
co_var[i][j] = covariancia(evo_val[i], evo_val[j], medias[i], medias[j])

#Calculating Correlation
co_rel = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):
for j in range(len(evo_val)):
if i == j:
co_rel[i][j] = 1
elif j < i:
co_rel[i][j] = co_rel[j][i]
else:
co_rel[i][j] = co_var[i][j] / (sqrt(co_var[i][i] * co_var[j][j]))

#Linear Solver
func_obj = [0.0 for i in range(co_x)]
DPRE = 0.0

RE = sum([func_obj[i]*medias[i] for i in range(len(evo_val))])

for i in range(co_x):
for j in range(co_x):
DPRE += func_obj[i]*func_obj[j]*co_var[i][j]

const = sum(func_obj) # must be equal to 1


What must I do? I need to minimize (DPRE/RE) with the constraints that sum(func_obj) must be equal to 1.



How can I call the solver? How can I tell the solver that my variables are in the array func_obj?



Thanks for the help!










share|improve this question

























  • Did you have a look at the documentation on NumPy minimization? This may be of help here...

    – sophros
    Nov 18 '18 at 15:27











  • @sophros Yes i did. The problem is i'm not used to work with optmizations and research problems, linear algs, etc... i don't know which func of the linalg should I use, i don't know how to tell the variables, the constraints. I didn't find and example that's close enough to my problem i guess.

    – Thomas Leick
    Nov 18 '18 at 16:32














0












0








0








I'm trying to solve a linear equation problem with constraints but I have no idea of how to call the solver.



I'm using a function that I wrote called covariancia but there's no problem with it, so I'll not post it here.



from funcs import covariancia
from math import sqrt
def main():
print("Iniciando Moneta...")
evo_val =
with open("evo_val.txt") as my_file:
evo_val = [line.split() for line in my_file]

#Montando array de Médias
medias =

for papel in evo_val:
media_atual = 0

for valor in papel:
media_atual += float(valor)

media_atual /= len(papel)
medias.append(media_atual)

#Calculating Covariance
co_x = co_y = len(evo_val)
co_var = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):

for j in range(len(evo_val)):
if (j < i):
co_var[i][j] = co_var[j][i]
else:
co_var[i][j] = covariancia(evo_val[i], evo_val[j], medias[i], medias[j])

#Calculating Correlation
co_rel = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):
for j in range(len(evo_val)):
if i == j:
co_rel[i][j] = 1
elif j < i:
co_rel[i][j] = co_rel[j][i]
else:
co_rel[i][j] = co_var[i][j] / (sqrt(co_var[i][i] * co_var[j][j]))

#Linear Solver
func_obj = [0.0 for i in range(co_x)]
DPRE = 0.0

RE = sum([func_obj[i]*medias[i] for i in range(len(evo_val))])

for i in range(co_x):
for j in range(co_x):
DPRE += func_obj[i]*func_obj[j]*co_var[i][j]

const = sum(func_obj) # must be equal to 1


What must I do? I need to minimize (DPRE/RE) with the constraints that sum(func_obj) must be equal to 1.



How can I call the solver? How can I tell the solver that my variables are in the array func_obj?



Thanks for the help!










share|improve this question
















I'm trying to solve a linear equation problem with constraints but I have no idea of how to call the solver.



I'm using a function that I wrote called covariancia but there's no problem with it, so I'll not post it here.



from funcs import covariancia
from math import sqrt
def main():
print("Iniciando Moneta...")
evo_val =
with open("evo_val.txt") as my_file:
evo_val = [line.split() for line in my_file]

#Montando array de Médias
medias =

for papel in evo_val:
media_atual = 0

for valor in papel:
media_atual += float(valor)

media_atual /= len(papel)
medias.append(media_atual)

#Calculating Covariance
co_x = co_y = len(evo_val)
co_var = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):

for j in range(len(evo_val)):
if (j < i):
co_var[i][j] = co_var[j][i]
else:
co_var[i][j] = covariancia(evo_val[i], evo_val[j], medias[i], medias[j])

#Calculating Correlation
co_rel = [[0]*co_y for i in range(co_x)]

for i in range(len(evo_val)):
for j in range(len(evo_val)):
if i == j:
co_rel[i][j] = 1
elif j < i:
co_rel[i][j] = co_rel[j][i]
else:
co_rel[i][j] = co_var[i][j] / (sqrt(co_var[i][i] * co_var[j][j]))

#Linear Solver
func_obj = [0.0 for i in range(co_x)]
DPRE = 0.0

RE = sum([func_obj[i]*medias[i] for i in range(len(evo_val))])

for i in range(co_x):
for j in range(co_x):
DPRE += func_obj[i]*func_obj[j]*co_var[i][j]

const = sum(func_obj) # must be equal to 1


What must I do? I need to minimize (DPRE/RE) with the constraints that sum(func_obj) must be equal to 1.



How can I call the solver? How can I tell the solver that my variables are in the array func_obj?



Thanks for the help!







python python-3.x numpy linear-programming solver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 15:22







Thomas Leick

















asked Nov 18 '18 at 5:54









Thomas LeickThomas Leick

13




13













  • Did you have a look at the documentation on NumPy minimization? This may be of help here...

    – sophros
    Nov 18 '18 at 15:27











  • @sophros Yes i did. The problem is i'm not used to work with optmizations and research problems, linear algs, etc... i don't know which func of the linalg should I use, i don't know how to tell the variables, the constraints. I didn't find and example that's close enough to my problem i guess.

    – Thomas Leick
    Nov 18 '18 at 16:32



















  • Did you have a look at the documentation on NumPy minimization? This may be of help here...

    – sophros
    Nov 18 '18 at 15:27











  • @sophros Yes i did. The problem is i'm not used to work with optmizations and research problems, linear algs, etc... i don't know which func of the linalg should I use, i don't know how to tell the variables, the constraints. I didn't find and example that's close enough to my problem i guess.

    – Thomas Leick
    Nov 18 '18 at 16:32

















Did you have a look at the documentation on NumPy minimization? This may be of help here...

– sophros
Nov 18 '18 at 15:27





Did you have a look at the documentation on NumPy minimization? This may be of help here...

– sophros
Nov 18 '18 at 15:27













@sophros Yes i did. The problem is i'm not used to work with optmizations and research problems, linear algs, etc... i don't know which func of the linalg should I use, i don't know how to tell the variables, the constraints. I didn't find and example that's close enough to my problem i guess.

– Thomas Leick
Nov 18 '18 at 16:32





@sophros Yes i did. The problem is i'm not used to work with optmizations and research problems, linear algs, etc... i don't know which func of the linalg should I use, i don't know how to tell the variables, the constraints. I didn't find and example that's close enough to my problem i guess.

– Thomas Leick
Nov 18 '18 at 16:32












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358284%2fhow-to-call-numpy-solver-to-minimize-a-obj-func-with-constraints%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358284%2fhow-to-call-numpy-solver-to-minimize-a-obj-func-with-constraints%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?