[BioC] RE : RE : Optimisation
Simon Noël
simon.noel.2 at ulaval.ca
Thu Feb 23 20:52:20 CET 2012
I tought that big formula will scare some people... But I will try... So I
have that function :
variance <- function(w, result)
{
w22 = w[1]
w21 = w[2]
w12 = w[3]
w11 = 1 - w12 - w21 - w22
( ((1/2 * w22)^2 * result[1]) + ((w21)^2 * result[2]) + ((w12)^2 *
result[3]) + ((2 * w11)^2 * result[4]) + (w22 * w21 * result[5]) + (w22
* w12 * result[6]) + (2 * w22 * w11 * result[7]) + (2 * w21 * w12 *
result[8]) + (4 * w21 * w11 * result[9]) + (4 * w12 * w11 * result[10]) )
}
I want to find the combinaison of value for my W that will give the best
minimisation of my equation. Each w must be between 1 and 0. Sum of all
om them must = 1.
Until now, everything seem to be ok. I use constrOptim like that :
Amat <- matrix(c(1,-1,0,0,0,0,0,0,1,-1,0,0,0,0,0,0,1,-1),6,3)
Bvec <- c(0,-1,0,-1,0,-1)
varLamda = constrOptim(theta=w, f=variance, grad=NULL, ui=Amat,
ci=Bvec, result = result)
result is defined as
variance1 <- function(i22, i21, i12, i11)
{
result = vector(length = 10)
result[1] = VLogRc(i22)
result[2] = VLogRc(i21)
result[3] = VLogRc(i12)
result[4] = VLogRc(i11)
result[5] = covlogi(i22, i21)
result[6] = covlogi(i22, i12)
result[7] = covlogi(i22, i11)
result[8] = covlogi(i21, i12)
result[9] = covlogi(i21, i11)
result[10] = covlogi(i12, i11)
result
}
and
covlogi <- function(i1, i2)
{
i = vector(length = length(i1))
for(j in 1:length(i1))
{
if(names(i1)[j] == names(i2)[j])
{
i[j] = 1/i1[j]
}else
{
i[j] = 0
}
}
sum(i)
}
VLogRc <- function(i)
{
( (1/i[1]) + (1/i[2]) + (1/i[3]) + (1/i[4]) )
}
my i are
#i11 = (q11 * q00) / (q10 * q01)
#i12 = (q12 * q00) / (q10 * q02)
#i21 = (q21 * q00) / (q20 * q01)
#i22 = (q22 * q00) / (q20 * q02)
i11[1] = Q[5]
i11[2] = Q[1]
i11[3] = Q[4]
i11[4] = Q[2]
i12[1] = Q[6]
i12[2] = Q[1]
i12[3] = Q[4]
i12[4] = Q[3]
i21[1] = Q[8]
i21[2] = Q[1]
i21[3] = Q[7]
i21[4] = Q[2]
i22[1] = Q[9]
i22[2] = Q[1]
i22[3] = Q[7]
i22[4] = Q[3]
and each of my Q are the number of subkect with a particular combinaison of
SNPs.
It may happen that one of the Q = 0. Like if q22 = 0, we will
have with VLogRc = ( (1/i[1]) + (1/i[2]) + (1/i[3]) + (1/i[4]) ) where i[1]
= 0 so the result is INF and that's really bad.
One way to avoid that is to write a new formula without w22.. And
an other when a problem come for w21 and an other for w11 and one other
for w12 and an other for w22 and w21, etc. There also a lot of if/else
for each possible q combinaison with 0 value. So it's not a goot
solution... Something simple is if I have an INF, and w = 0, ther
the problem will be solved...
If we take the exemple of q22 =0, w22 must = 0 in orther that the program
work... But how to corce that with constrOptim? Is there a better fonction
to solve my problem?
Simon Noël
CdeC
_________________________________________________________________
De : Tim Triche, Jr. [tim.triche at gmail.com]
Date d'envoi : 22 février 2012 16:11
À : Simon Noël
Cc : bioconductor at r-project.org
Objet : Re: [BioC] RE : Optimisation
you probably want to post this on r-help or perhaps look at the optimx
package.
you might also want to include a piece of code showing what precisely it is
that you are trying to do.
this is more likely to get a response than the fairly vague message below.
hope it helps,
--t
2012/2/22 Simon Noël <[1]simon.noel.2 at ulaval.ca>
Hello,
Anyone can help?
Simon Noël
CdeC
_________________________________________________________________
De : Simon Noël
Date d'envoi : 9 février 2012 13:37
À : [2]bioconductor at r-project.org
Objet : Optimisation
Hi every one,
I have a big formula with some parameter that I want to minimise with some
condition like sum of all of them must be one, in some condition, one
of them must equal 0, etc.
I am trying to solve that with constrOptim but I got some broblem... Like
how to have a parametter equal to 0 Is there any package who is more
user friendly that you can suggest to me?
Simon Noël
CdeC
_______________________________________________
Bioconductor mailing list
[3]Bioconductor at r-project.org
[4]https://stat.ethz.ch/mailman/listinfo/bioconductor
Search the archives:
[5]http://news.gmane.org/gmane.science.biology.informatics.conductor
--
A model is a lie that helps you see the truth.
[6]Howard Skipper
References
1. mailto:simon.noel.2 at ulaval.ca
2. mailto:bioconductor at r-project.org
3. mailto:Bioconductor at r-project.org
4. https://stat.ethz.ch/mailman/listinfo/bioconductor
5. http://news.gmane.org/gmane.science.biology.informatics.conductor
6. http://cancerres.aacrjournals.org/content/31/9/1173.full.pdf
More information about the Bioconductor
mailing list