What is the Derivative of a Vector Field in a Manifold?

Question: I'm studying the book "Geometric Theory of Dynamical Systems
An Introduction" - Jacob Palis, Jr. Welington de Melo.
On page 10, the author defines:

Let $M^m\subset \mathbb{R}^k$  be a differentiable manifold. A vector field of class $C^r$ on M is a $C^r$ map $X: M \rightarrow \mathbb{R}^k$ which associates a vector $X(p) \in T_pM$ to each point $p \in M$. This corresponds to a $C^r$ map $X: M \rightarrow TM$ such that $\pi X$ is the identity on $M$ where $\pi$ is the natural projection from $TM$ to $M$. We denote by $\mathfrak{X}^r (M)$ the set of $C^r$ vector fields on $M$.

And on page 58, comes the definition that I'm having problem

Let $X \in \mathfrak{X}^r(M)$ and let $p\in M$ be a singularity of $X$. We say that $p$ is a hyperbolic singularity if $DX_p: T_p M \rightarrow T_p M $ is a hyperbolic linear vector field, that is, $DX_p$ has no eigenvalue on the imaginary axis.

I don't understand why $DX_p: T_pM \rightarrow T_pM$.  My knowledge of Differential Topology just allows me to differentiate functions like $f: M \rightarrow N$, implying that $Df_p: T_pM \rightarrow T_{f(p)} N$, so (in my mind) the correct would be $DX_p:T_pM \rightarrow T_{X(p)}\mathbb{R}^k$, so talk about eigenvalue on $DX_p$ doesn't make sense, because $DX_p$ is not a endomorphism.
The most strange part is that $T_pM$ isn't even isomorphic to $T_{X(p)}\mathbb{R}^k$. Can anyone tell me what am I confusing?
Answer: View $X$ as a smooth map $X \colon M \to TM$ with the property that $\pi X = 1_M$ where $\pi \colon TM \to M$ is the projection map.  As $X$ is a smooth map between manifolds it has a derivative $DX_p \colon T_p M \to T_{X(p)} TM$ defined just like the derivative of any smooth map.  This does indeed look like a problem: the vector space on the left has dimension $\dim(M)$ while the one on the right has dimension $2 \dim(M)$, so it doesn't make sense to speak of eigenvalues!
But $X$ isn't just any old smooth map: we haven't used the equation $\pi X = 1_M$ yet.  Let us differentiate both sides of this equation using the chain rule:
$$D\pi_{X(p)} \circ DX_p = 1_{T_p M}$$
Trivializing everything over a coordinate neighborhood of $p$, we have $T_{X(p)} TM \cong \mathbb{R}^n \times \mathbb{R}^n$ and $T_p M \cong \mathbb{R}^n$; in this trivialization $D\pi_{X(p)}$ is just the projection map onto the first factor.  Thus the equation above says that $DX_p$ has to have the form
$$DX_p(v) = (v, Lv)$$
for some linear transformation $L \colon \mathbb{R}^n \to \mathbb{R}^n$.  It is a fairly standard abuse of notation to think of this object $L$ as "the derivative" of $X$, even though the derivative is really $(I, L)$ where $I$ is the identity.
Comment: The first time I that read it was very clear, but now I'm facing a mortal doubt. Your linear transformation $L$ depends on the trivializations  that makes $T_{X(p)} TM \cong \mathbb{R}^{2n}$ and $T_pM \cong \mathbb{R}^n$. How do you know that $L$ be hyperbolic doesn't depend on the trivializations of its construction.
Comment: @MatheusManzatto Note that we must trivialize $TM$ and $TTM$ over the same coordinate neighborhood $U$ of $p$ to guarantee that $D\pi_{X(p)}$ and $DX_p$ have the from I described.  If we trivialize over a different coordinate neighborhood $U'$, then the corresponding $L'$ will be the conjugate of $L$ by the derivative of the transition map between the charts for $U$ and $U'$.  Conjugation preserves diagonalizability, eigenvalues, etc. so everything is fine.
Comment: Fantastic answer, thanks.
Answer: It is possible to minorly adapt the answer by Paul Siegel in order to avoid trivializations. We just use the natural split over a point $(p,0)$ of $T_{(p,0)}TM$.
Again, a vector field is a map $X: M \to TM$ such that $\pi \circ X=\mathrm{Id}$.
If $X(p)=0$, we have that $dX_p:T_pM \to T_{(p,0)}TM \simeq T^h_{(p,0)}TM\oplus T^v_{(p,0)}TM,$
where
$$T^h_{(p,0)}TM:=\{\dot{\gamma}(0) \mid \gamma \text{ is a curve through $(p,0)$ such that } \gamma \subset M\},$$
$$T^v_{(p,0)}TM:=\{\dot{\gamma}(0) \mid \gamma \text{ is a curve through $(p,0)$ such that } \gamma \subset T_{p}M\}.$$
Note that the existence of such a natural decomposition uses heavily the fact that $X(p)=0$, otherwise we would need to rely on a metric (more directly, a connection) on $M$ to furnish it (for more information, see here).
There is a natural isomorphism $i: T^v_{(p,0)}TM  \to T_pM $ (It is similar to the isomorphism that exists from $T_pV \to V$, where $V$ is a vector space). The "derivative" which the text is alluding to is then
$$DX_p=\iota \circ \pi_2 \circ dX_p.$$
Answer: Since $M$ is a manifold, there is a neighborhood $U$ of $p$ and a chart $U\to\Bbb R^m$. In particular, it determines an isomorphism $T_pM\cong\Bbb R^m$, and the tangent manifold over $U$ is isomorphic to the trivial fibration $U\times T_pM$. (We can flatten it locally.)
So, locally (i.e., over $U$) we can regard the vector field $X$ as $U\to T_pM$.
(We could as well write $U\to\Bbb R^m$ if that's clearer.)
Finally, as $T_pM$ is a linear space, its tangent space (on any point) is identified with itself.


Dynamic dependent form select inputs

Question: I'm building a custom dependent dropdown form with 2 select inputs.
I've managed to build the form inputs and update them accordingly, but I'm not able to get the dependent select's value in the submit hook.
I think this happens because I changed (via AjaxResponse()/ReplaceCommand) the $form in the AJAX callback, and as such, the second input values aren't updated in the $form_state.
My problem is that I have no simple way of knowing which options will be available either in the first-level select nor in the dependent select, since they come from a 3rd-party API.
Is there any way I can trigger the update of the #options in the dependent select, without having to render the nested dropdown and changing the $form so that the nested values are available in the submit hook?
Or, alternatively, is there anyway I can update the $form_state so that it knows the newly added #options of the second select?
Comment: See the topic "The Big Idea" in https://www.drupal.org/docs/7/api/javascript-api/ajax-forms-in-drupal-7
Comment: Please go ahead with your answer, sure this will help a lot of people, because ajax callbacks are a bit counterintuitive. I will upvote it.
Comment: $form is rebuilt in each ajax request before your ajax callback is even invoked. And then in your callback you are only allowed to use form elements from $form, because otherwise the form element is not processed and can't be submitted.
Comment: @4k4 thanks for your feedback, but I'm not sure what you mean. My dependent select element already exists in the form when it is first built, it just doesn't have the `#options` populated. After I populate them in the AJAX callback, they show up in the markup, but aren't available in the submit hook to be processed. Can you suggest how to handle this?
Comment: You populate the options in the form rebuild. The form build function knows that it is rebuilding when $form_state is filled with user input, which it is not on the first build.
Comment: I'm struggling a bit with your remarks. Can you point me to some documentation regarding this?
Comment: @4k4 I got it working with your help and those docs, thank you! If you want to create an answer based on this, I'll be happy to mark it as accepted. I'll write my own though, so I can clear up my misconceptions and hopefully help someone else.
Answer: With @4k4's help I managed to find the root cause of my issue and fix it.
I was wrongfully assuming that the $form elements could be somehow modified in an AJAX call to produce my desired effect.
While it is true that the elements could be modified and re-rendered in an AJAX response, that is not the correct way to alter a form after an AJAX call.
The 2 main things to know are:

forms are rebuilt everytime an AJAX call is made (when it is declared in the #ajax array of the form element triggering the call)
the AJAX function being called should (ideally) only return the element suffering modifications. It cannot modify the $form in any way, otherwise those modification will either be lost when it is rebuilt, or trigger the An illegal choice has been detected. Please contact the site administrator. message.

This being said, the general flow for this should be:

create the buildForm function with code that builds both your select elements. Wrap in a conditional clause code that tests if the parent select was already changed or not. This will be used to determine if the nested select should be populated or not;
set an #ajax property in the parent select element of the form, referring a callback to be used;
define the callback to return only the element which needs to change in the form, ie, the nested select;
when Drupal tries to rebuild the form, your parent select will already have a value that can be used in the above mentioned test-clause to allow for population of the nested callback.

@4k4's suggested documentation was difficult for me to find, but clear enough to follow trough once found - link here. (Even though it is for Drupal 7, in Drupal 8 it functioned exactly the same way).

Dynamic dependent form select inputs


(Shell) Create a recursive function which return the basename of files, preserving hirarchy

Question: Currently, I have the following:
#!/bin/sh

pathlink() {
  for file in "$@";
  do
    if [ -d "$file" ];
    then
#      echo "$file"
      pathlink "$file/*"
    else
      echo '/home/buddhilw/dotfiles/'$(basename $file)
#       ln -nfs /home/buddhilw/dotfiles/$(basename $directory) $directory
    fi
  done
}

pathlink \
  /home/buddhilw/.config/* \
  /home/buddhilw/.local/* \
  /home/buddhilw/.bashrc

I get the following error, for every file in upper-directories,
basename: extra operand '/home/buddhilw/.local/quicklisp/dists'

Comment: Btw.: `sh` ([Bourne-shell](https://en.wikipedia.org/wiki/Bourne_shell)) is usally not `bash` ([Bourne-again shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell))).
Comment: change `pathlink "$file/*"`  to  `pathlink $file/*`
Comment: @YuriGinsburg: This would get you in trouble, if `file` contains spaces. I would do a `pathlink "$file"/*`.
Comment: @BuddhiLW : I changed your tag _bash_ into _shell_, because there is nothing in your question related to bash. May I suggest that you also update the question's title accordingly?
Answer: change basename $file to basename "${file}". It likely just ran into a filename with a space in it.
i would suspect you'd have an easier time leaving this kinda stuff up to the find utility.
find /some/path -printf '%d %y %Y %f\n'

provides all the info you need as far as i can see. the first column indicating the depth, the 2nd and 3rd indicating the filetype (like d for directories; one follows symlinks one does not), and the 4th column being the file's basename.
you can put that command in a bash script, change the \n to \0, pipe it into a while loop with IFS=" " read -r -d$'' DEPTH TYPEA TYPEB FILENAME and you have a very well rounded filescanner.
Comment: The braces don't add any value here; `basename "$file"` is quite sufficient and idiomatic.
Comment: never a downside really, i always brace them all :)
Comment: It is not sufficient to quote the argument of `basename`. It is necessary to quote the sub-shell expression as well: `"$(basename "$file")"`.


Finding Groups and Subgroups Such That Some Relations (and Homomorphism) Hold

Question: Find groups $G$ and $G'$ and a homomorphism $f : G \to G'$ so that there are subgroups $U_1, U_2 \leq G$ (with $U_1 \neq U_2$) and $U'_1, U'_2 \leq G'$ for which following diagram is true.

In particular, this means that

$f(U_2) = U'_1 = f(U_1)$;
$f^{-1} (U'_1) = U_2 = f^{-1}(U'_2)$; and
there is no subgroup $U_3 \leq G$ so that $f(U_3)=U'_2.$

I thought about $f:(\mathbb{Z}, +)\rightarrow (\mathbb{Z}, +)$ with $x \mapsto 2x$ (which is a homomorphism).
Then, I chose $U_1=(\mathbb{Z}_e,+)=U'_1,$ which is the subgroup of even integers, $U_2=(\mathbb{Z},+)=U'_2,$ which is clearly the (trivial) subgroup of all integers.
Since the function only maps to even numbers, there is no subgroup $U \leq G$ so that $f(U)=U'_2$.
And since the inverse image of the odd numbers has no element, it follows that $f^{-1} (U'_1) = U_2 = f^{-1}(U'_2)$
Lastly, $f(U_1) \overset{!}{=} U'_1,$ but I'm not too sure about that since I would need all the odd numbers to truly map to every element of $U'_1.$

Could anyone give me a hint how to resolve the last problem or give me a better example?
Comment: You need to be more careful to get details correct.
Comment: @Quotenbanane Well, you've not specified $f^{-1}(U_1') \ne U_1$ either. You've only stated that $f^{-1}(U_1') = U_2$, which in itself does not imply the former, unless you explicitly specify $U_1 \ne U_2$.
Comment: I have withdrawn my comment! But does your example work if you define $U_1$ to be all integers rather than just the even integers?
Comment: @DerekHolt I don't think so... because then $f(U'_1)=U_1$ but that shouldn't be the case.
Comment: But in your problem statement you have said that you do want $f(U_1') = U_1$.
Comment: @DerekHolt Oh sorry, I meant to write $f^{-1}(U'_1)=U_1$
Comment: @DerekHolt Like drawn in the diagramm.
Comment: @DerekHolt yeah but in my question I wrote it right so thankfully no big mistake.
Comment: @Quotenbanane Clearly, you also need $U_1 \ne U_2$, right? You've not stated it, but without that assumption there's nothing stopping you from taking $U_1 = U_2$ in your own example (plus, even mentioning $U_1$ in the statement would be pointless). So please add that to your question.
Comment: @M.Vinay They don't need to be different. But why would we choose $U_1 = U_2$ if we want $f^{-1}(U'_1) = U_2$ but not $f^{-1}(U'_1) = U_1$
Comment: @M.Vinay You're right. I'll specify it immediately.
Answer: Take $G = \mathbb Z_{12}$ and $G' = \mathbb Z_{18}$.
Define $f \colon G \to G'$ by $f(1_G) = 6_{G'}$ (and extend).
Then $f$ is a homomorphism with $\operatorname{im} f = \langle 6_{G'} \rangle = \{0, 6, 12\}$.
Let $U_2' = G' = \mathbb Z_{18}$, $U_2 = G = \mathbb Z_{12}$. Note that $f^{-1}(U_2') = U_2$.
But $f$ is not surjective, so $\not\exists U_3 \le G$ such that $f(U_3) = U_2'$.
Let $U_1 = \langle 2_G \rangle = \{0, 2, 4, 6, 8, 10\} \le \mathbb Z_{12}$.
Let $U_1' = \langle 6_{G'} \rangle = \{0, 6, 12\} \le \mathbb Z_{18}$.
Note that $f(U_2) = \operatorname{im} f = U_1'$.
But also, $f(U_1) = \{f(0), f(2), f(4), f(6), f(8), f(10)\} = \{0, 12, 6, 0, 12, 6\} = \{0, 6, 12\} = U_1'$.


file permissions on shared host

Question: I'm on a shared host, and a bit confused about file permissions:

My website directory /home/user/www is owned by user:nobody
Everything inside /home/user/www is owned by user:user (?)

Most people would tell me I have to do the following (summarized):
chown -R user:nobody /home/user/www
find /home/user/www -type d -exec chmod 750 {} \;
find /home/user/www -type f -exec chmod 640 {} \;

But I can't `chown' anything, and since files will be owned by user:user, I don't know what the permissions should be.
I noticed I can chmod 600 some PHP scripts, while CSS stylesheets need to be world readable..?
I'm looking for the best security approach in this case! And please don't tell me I need to move to a dedicated server: why would I ask any question then!?
Comment: What does your hosting-provider's help-desk say?
Comment: They're very busy and have been answering to emergency requests only. I had a look at their Knowledgebase, and it says I should chmod my PHP scripts to 644 'in order to avoid problems'. Is the only security risk of making my files readable by everybody the ability of reading passwords etc.? If it is, then I would chmod everything to 644, and config.php I would chmod 600.
Answer: The files in the site www subdirectory should be readable by the effective user-id of the running web-server. The Apache web-server often runs as user nobody, group nobody or user www-data, group www-data. So this user or group needs read permissions.
If the PHP scripts write to files, those files need to be writeable by the effective user-id of the running Apache service.
How exactly this is arranged depends on your hosting provider.
If the site is public and the scripts contain no passwords, no exploitable security loopholes (e.g. race conditions), it may be OK to give world-read permissions. I would aim to have all files owned by your personal user-id, not by a user "nobody" or "user". Only you should have write permissions on files in the www subdirectory (and it's subdirectories). Even if your site contains no personal or valuable data - you don't want it to become taken over by fraudsters or spammers.
A couple of useful resources are

http://hostingfu.com/article/running-php-on-shared-hosting
http://phpsec.org/projects/guide/
Comment: Thanks, useful articles! From what I understood, PHP scripts are run as my_user (I tried a exec('whoami')), not by nobody, so it might be probably OK to leave them 600 (a few contain passwords). I think other files have to be left as 644 because the files don't belong to the apache group, and apache doesn't belong to my group. Am I wrong? When you said the files should be owned by the user-id: I tried chowning some files on my Debian machine as 1000:1000, but `ls -l' still shows username:username. Does it make any important difference? The server runs CentOS (Red Hat), though. Thanks
Comment: I realize you were not talking about the user number, but that the user name shouldn't be 'user'. It was just an example!

file permissions on shared host


How to stop cache_field table from growing?

Question: I have a website with LOTS of nodes and LOTS comments. I have lesser space in the hosting plan and don't wont to buy more. The cache_field table of the site keeps on growing due to caching.
I disabled "Cache pages for anonymous users" in admin/config/development/performance and kept
"Cache blocks" enabled. The current performance and load time with the current settings and after a cache clear is at an OK level. But still the cache_field grows. Same with the "Cache blocks" disabled.
Due to the size of the site I feel that caching of nodes and comment are not necessary.
How to stop cache_field table from growing?
More:

I'm ok with coding
I have a VPS with 20GB Disk, and 60% filled when cache is cleared. Once I cleared the cache when it was 75% filled and growing (with the cached data).
Sorry for the late data I have 512MB ram.
Comment: What are the limitation of your current host? DB size, HD space, etc...
Comment: I have a VPS with 20GB Disk, and **60% filled without caching** and I once cleared the cache when it was **75% filled with the cache**.
Comment: Can't you just kick that into a memory cache? Do you have enough RAM and control to use APC or memcached?
Comment: 512MB RAM for a site with a lot of comments? Typical installation profile will easily require 128MB just to install, and then 16-32MB per uncached client. So even if your OS does not need memory at all (idealistic case) your server could possibly be crashed by mere 16 people. Have you tested actual memory usage before you decided you do not need so much caching?
Comment: @Molot Thanks a lot for the pointing out. I actually have not done testing much. I cleared the cache when there are lot of people and at that time the load time was OK. I'm waiting for more traffic and then planning to go for a VPS plan with better resources.
Answer: You could switch that cache bin so it uses something like file cache https://drupal.org/project/filecache
Also look into using memcache as that will evict the older cache data so that memcache stays within the parameters you give it.
Also consider optimizing the database; it should help to reduce the overhead
http://dominiquedecooman.com/optimize-mysql-tables-gives-35-drop-disk-usage-drupal-7-performance-tip
Finally if you really want to disable that cache you can use the DrupalFakeCache backend for those cache bins
https://drupal.org/node/797346
Comment: Thanks @Mikeyton2. But It will also cache and use my remaining space. Is there a way to stop the caching?
Comment: Thanks @Mikeyton2, https://drupal.org/node/797346 seems to disable the cache. Thanks!
Answer: If it's VPS, then you probably have enough control over it to use APC or memcached. Modules that may help with it:

APC - Alternative PHP Cache
Memcache API and Integration
Memcache Storage

And probably more. But they all are based on the same philosophy:

Keep data in RAM, as disk access is slow
Have a limited amount of storage, that never can be crossed
If there is too much data, silently delete the least used elements

So just move cache_field bin to RAM and all your problems should be solved.
Comment: I already use [Memcache Storage](https://drupal.org/project/memcache_storage). But the cache_field is still written to the mysql database. Is there any option I forgot?


Negative Binomial GLM confusing effect on p value of model by changing theta

Question: I am interested in generating a p-value for two small groups of count based data that I believe to show overdispersion. The groups are for example:
library(MASS)
set.seed(106)
# True mean for treated is 100 and control is 10.
counts <- c(rnegbin(4, 100, 0.5), rnegbin(4, 10, 0.5))
condition <- c(rep("treated", 4), rep("control", 4))
example_df <- data.frame(counts, condition)
example_df
counts  condition
4       treated
9       treated
111     treated
31      treated
13      control
1       control
7       control
9       control

This is just a toy example, from real data it would be difficult to estimate dispersion from just 8 values, so for my real data I want to use a wide range of theta values to determine how overdispersed the data would need to be to generate p values above the common 0.05 threshold.
My idea was to model the counts using the negative binomial distribution with different theta values.
As I understand it theta is an estimate of dispersion calculated as:

This is my issue and where I think I have a mistake in my thinking:
As theta increases variance should then be closer to the mean. I would expect this to mean that the regression should show a lower p value as low variance would result in a larger difference between the means of the control and the treated. Yet the opposite is observed:
glm(formula = counts ~ condition, family = negative.binomial(theta = 100),
data = example_df)
summary(neg_bin_fit)

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)
(Intercept)            2.0149     0.9352   2.155   0.0746 .
conditiontreated       1.6422     1.0455   1.571   0.1673

neg_bin_fit <- glm(counts~condition, family=negative.binomial(theta=.1), data=example_df)

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)
(Intercept)        2.0149     0.5122   3.934  0.00768 **
conditiontreated   1.6422     0.7224   2.273  0.06339 .

I may be thinking of this wrong, should I model the treated and control counts separately and then use something like anova to compare the results?
Thank you
Answer: I would not suggest modelling the counts from the control and treatment branches separately. Treating within the same model is perfectly reasonable conceptually in this case as well as very beneficial computationally if we do not have a huge sample.
I think that your basic understanding about how $\theta$ works is fine. What I think is misinterpreted is the fact that a lower $p$-value is directly associated with a lower (or greater) $\theta$. The $p$-value associated with the $\beta$ coefficient of the treatment effect is related to the success of the Fischer scoring algorithm doing the fitting, i.e. the negative binomial model with parameters that solve the maximum likelihood equation. This MLE model does not necessary have the "smallest $p$-values", it "only" has the maximum likelihood. If we use a routine like glm.nb we will iteratively estimate both the $\beta$ coefficients as well as the $\theta$ parameter that are associated with the MLE. We could then use AIC or other information criteria to also examine if it is optimal or not. (Because we fitted using MLE, by definition, for that set of covariates $X$, that $\theta$ will be the optimal one. ) The aptly named CV.SE thread: How does glm.nb work? gives more details on how glm.nb works.


Controlling for confounding variables with multiple regression - isn't correlation a problem?

Question: From the Wikipedia definition - "a confounder (also confounding variable, confounding factor, or lurking variable) is a variable that influences both the dependent variable and independent variable, causing a spurious association."
So to my understanding, a confounder would usually be correlated with the main independent variable, as it influences it.
One way to control for a confounder would be to add it to the multiple regression model. But in the context of machine learning it is said that having correlated features in the model should be avoided. In particular, it was answered in the following question: https://datascience.stackexchange.com/questions/36404/when-to-remove-correlated-variables
"But if are concerned about interpretability then it might make sense to remove one of the variables, even if the correlation is mild. This is particularly true for linear models. One of the assumptions of the linear regression is lack of perfect multicollinearity in the predictors.
If A is correlated with B, then you cannot interpret the coefficients of neither A nor B. To see why, imagine the extreme case when A=B (perfect correlation). Then, the model y=100A+50B is the same as the model y=5A+10B or y=-2000A+4000B. There are multiple equilibra in the possible solutions to the least square minimzation problem therefore you cannot "trust" neither."
So to my understanding, if the confounder we add to the multiple regression model is correlated(which to my understanding is usually the case) with the independent variable,  we will not be able to interpret the coefficients appropriately, so how could we actually understand the relationship between the main independent variable and the dependent variable?
Comment: Another way to control for a confounding variable is to do your linear regressions separately for different values of the confounder. I'm not so sure you can't interpret the coefficients appropriately.
Comment: There's a difference between being correlated and being perfectly correlated.
Comment: Could you please explain how $100A + 50B = 5A + 10B = 2000A + 4000B?$
Answer: The statements

But if are concerned about interpretability then it might make sense to remove one of the variables, even if the correlation is mild.

and

One of the assumptions of the linear regression is lack of perfect
multicollinearity in the predictors.

are unrelated to each other. Perfect multicolinearity is not the same as a correlation between predictors. You do not ever have to think about perfect multicollinearity because all regression software will drop one of a pair of perfectly colinear predictors (though if you're doing regression by hand, perfect multicolinearity will cause a problem in inverting the matrices). Perfect multicolinearity is a problem of making a mistake in specifying your model, not a statistical problem.
Correlated predictors are not a problem at all for regression because regression extracts the unique contribution of each predictor to the outcome. Because most of the loss functions used to estimate the coefficients have a global minimum and are convex, there is only one solution to the regression estimation problem and the issue of multiple coefficient vectors being compatible with the same solution is absent.
It is indeed true that the more correlated predictors are, there less precision there is in estimating their effect, precisely because there is less information available to distinguish the unique effects of the predictors from each other. But this is not something the analyst gets to control except in an experiment; correlations among observed predictors are a product of nature. Failing to include a predictor necessary to control confounding in a model because it is correlated with the focal predictor will leave your effect estimate biased (although there is some work on managing the bias-variance trade-off by dropping predictors with certain qualities; e.g., Wu et al. (2011)).


Yii model overriding

Question: is it possible to override the methods in the yii model. for example i have a model name Books and i need to override all the rules written in the Model. now the Books model have 3 rules defined. what i do is make a new class BooksExt extends the Books model.
<code>class BooksExt extends Books {
 public function rules() {
   return array();
   // i am not using the parent::rules() inside this.
   // i dont need to use the rules for this model.
 }
 public function search() {
   return 'search override';
   // does this function also get override.
 }
}
</code>
does i write a blank rules() method removes all the rules and when i call
<code>$model = new AccountsPrefferredSuppliersExt;
$model->search();
</code>
its printing search override. does it accept the rules as empty array.
friends can you just check and please responds.
thanks in advance.. have a nice day
Comment: It's not at all clear what you're asking.  Yes, you can overwrite functions in Books by putting them in BooksExt. Your best bet is just to try it out!
Comment: yes i tried it. waiting for some others experience.
Answer: Yes, method rules() in BooksExt will return an empty array.
Read about Class Hierachies And Overriding.

Yii model overriding


Android Studio ScrollView - Existe alguma maneira de Modificar o tamanho via codigo?

Question: A dúvida é o seguinte... Tenho um Vertical ScrollView com 20 botões posicionados em 5x2 na view, quando uso o scroll vejo os outros 10 botões que estão escondidos, porém esses botões ficam invisíveis caso não tenha funções definidas no select do banco que uso pra popular os botões... Ai vem o grande problema, o scrollView ainda rola ate o ultimo botão mesmo que este esteja invisível, tem alguma forma de não deixar rolar além dos botões q estão visíveis?
<code><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dev_03.sabbemobile.Telas.Pedidos.BarRestaurante.FastFood.FastFoodPedidos.FastFoodPedidoActivity$PlaceholderFragment">

<TextView
    android:id="@+id/textView18"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/scrTabRef1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="19dp"
    android:text="Sobremesas"
    android:textAllCaps="true"
    android:textColor="@android:color/background_dark"
    android:textStyle="bold" />

<TextView
    android:id="@+id/textView17"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="Bebidas"
    android:textAllCaps="true"
    android:textColor="@android:color/background_dark"
    android:textStyle="bold" />

<ScrollView
    android:id="@+id/scrTabRef1"
    android:layout_width="wrap_content"
    android:layout_height="195dp"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/textView17">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/btnTabRfrRfr1"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr2"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrRfr1"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr3"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrRfr2"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr4"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrRfr3"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr5"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrRfr4"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr6"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnTabRfrRfr1"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr7"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr2"
            android:layout_toRightOf="@+id/btnTabRfrRfr6"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr8"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr3"
            android:layout_toRightOf="@+id/btnTabRfrRfr7"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr9"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr4"
            android:layout_toRightOf="@+id/btnTabRfrRfr8"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr10"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr5"
            android:layout_toRightOf="@+id/btnTabRfrRfr9"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr11"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnTabRfrRfr6"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr12"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr7"
            android:layout_toRightOf="@+id/btnTabRfrRfr11"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr13"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr8"
            android:layout_toRightOf="@+id/btnTabRfrRfr12"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr14"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr9"
            android:layout_toRightOf="@+id/btnTabRfrRfr13"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr15"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr10"
            android:layout_toRightOf="@+id/btnTabRfrRfr14"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr16"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnTabRfrRfr11"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr17"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr12"
            android:layout_toRightOf="@+id/btnTabRfrRfr16"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr18"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr13"
            android:layout_toRightOf="@+id/btnTabRfrRfr17"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr19"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr14"
            android:layout_toRightOf="@+id/btnTabRfrRfr18"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrRfr20"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrRfr15"
            android:layout_toRightOf="@+id/btnTabRfrRfr19"
            android:background="@drawable/button_pressed"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

    </RelativeLayout>
</ScrollView>

<ScrollView
    android:id="@+id/scrTabRef2"
    android:layout_width="wrap_content"
    android:layout_height="130dp"
    android:layout_below="@+id/textView18"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="9dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/btnTabRfrSbm1"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm2"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrSbm1"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm3"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrSbm2"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm4"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrSbm3"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm5"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/btnTabRfrSbm4"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm6"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnTabRfrSbm1"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm7"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm2"
            android:layout_toRightOf="@+id/btnTabRfrSbm6"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm8"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm3"
            android:layout_toRightOf="@+id/btnTabRfrSbm7"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm9"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm4"
            android:layout_toRightOf="@+id/btnTabRfrSbm8"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm10"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm5"
            android:layout_toRightOf="@+id/btnTabRfrSbm9"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm11"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnTabRfrSbm6"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm12"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm7"
            android:layout_toRightOf="@+id/btnTabRfrSbm11"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm13"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm8"
            android:layout_toRightOf="@+id/btnTabRfrSbm12"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm14"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm9"
            android:layout_toRightOf="@+id/btnTabRfrSbm13"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm15"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm10"
            android:layout_toRightOf="@+id/btnTabRfrSbm14"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm16"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/btnTabRfrSbm11"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm17"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm12"
            android:layout_toRightOf="@+id/btnTabRfrSbm16"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm18"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm13"
            android:layout_toRightOf="@+id/btnTabRfrSbm17"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm19"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm14"
            android:layout_toRightOf="@+id/btnTabRfrSbm18"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btnTabRfrSbm20"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_below="@+id/btnTabRfrSbm15"
            android:layout_toRightOf="@+id/btnTabRfrSbm19"
            android:background="@drawable/button_pressed_green"
            android:text="Button"
            android:textColor="@android:color/background_light"
            android:textSize="12sp" />

    </RelativeLayout>
</ScrollView>

<Button
    android:id="@+id/btnTabRfrFinalizar"
    android:layout_width="95dp"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:background="@drawable/button_pressed"
    android:text="Finalizar Pedido"
    android:textColor="@android:color/background_light"
    android:textSize="12sp" />

<Button
    android:id="@+id/btnTabRfrVoltar"
    android:layout_width="95dp"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/button_pressed"
    android:text="Voltar"
    android:textColor="@android:color/background_light"
    android:textSize="12sp" />
</code>

<code>    //TODO DECLARAÇÃO DOS BOTÕES REFRI
    btnRefri[0] = rootView.findViewById(R.id.btnTabRfrRfr1);
    btnRefri[1] = rootView.findViewById(R.id.btnTabRfrRfr2);
    btnRefri[2] = rootView.findViewById(R.id.btnTabRfrRfr3);
    btnRefri[3] = rootView.findViewById(R.id.btnTabRfrRfr4);
    btnRefri[4] = rootView.findViewById(R.id.btnTabRfrRfr5);
    btnRefri[5] = rootView.findViewById(R.id.btnTabRfrRfr6);
    btnRefri[6] = rootView.findViewById(R.id.btnTabRfrRfr7);
    btnRefri[7] = rootView.findViewById(R.id.btnTabRfrRfr8);
    btnRefri[8] = rootView.findViewById(R.id.btnTabRfrRfr9);
    btnRefri[9] = rootView.findViewById(R.id.btnTabRfrRfr10);
    btnRefri[10] = rootView.findViewById(R.id.btnTabRfrRfr11);
    btnRefri[11] = rootView.findViewById(R.id.btnTabRfrRfr12);
    btnRefri[12] = rootView.findViewById(R.id.btnTabRfrRfr13);
    btnRefri[13] = rootView.findViewById(R.id.btnTabRfrRfr14);
    btnRefri[14] = rootView.findViewById(R.id.btnTabRfrRfr15);
    btnRefri[15] = rootView.findViewById(R.id.btnTabRfrRfr16);
    btnRefri[16] = rootView.findViewById(R.id.btnTabRfrRfr17);
    btnRefri[17] = rootView.findViewById(R.id.btnTabRfrRfr18);
    btnRefri[18] = rootView.findViewById(R.id.btnTabRfrRfr19);
    btnRefri[19] = rootView.findViewById(R.id.btnTabRfrRfr20);
    btnRefri[0].setVisibility(View.INVISIBLE);
    btnRefri[1].setVisibility(View.INVISIBLE);
    btnRefri[2].setVisibility(View.INVISIBLE);
    btnRefri[3].setVisibility(View.INVISIBLE);
    btnRefri[4].setVisibility(View.INVISIBLE);
    btnRefri[5].setVisibility(View.INVISIBLE);
    btnRefri[6].setVisibility(View.INVISIBLE);
    btnRefri[7].setVisibility(View.INVISIBLE);
    btnRefri[8].setVisibility(View.INVISIBLE);
    btnRefri[9].setVisibility(View.INVISIBLE);
    btnRefri[10].setVisibility(View.INVISIBLE);
    btnRefri[11].setVisibility(View.INVISIBLE);
    btnRefri[12].setVisibility(View.INVISIBLE);
    btnRefri[13].setVisibility(View.INVISIBLE);
    btnRefri[14].setVisibility(View.INVISIBLE);
    btnRefri[15].setVisibility(View.INVISIBLE);
    btnRefri[16].setVisibility(View.INVISIBLE);
    btnRefri[17].setVisibility(View.INVISIBLE);
    btnRefri[18].setVisibility(View.INVISIBLE);
    btnRefri[19].setVisibility(View.INVISIBLE);
    btnRefri[0].setClickable(false);
    btnRefri[1].setClickable(false);
    btnRefri[2].setClickable(false);
    btnRefri[3].setClickable(false);
    btnRefri[4].setClickable(false);
    btnRefri[5].setClickable(false);
    btnRefri[6].setClickable(false);
    btnRefri[7].setClickable(false);
    btnRefri[8].setClickable(false);
    btnRefri[9].setClickable(false);
    btnRefri[10].setClickable(false);
    btnRefri[11].setClickable(false);
    btnRefri[12].setClickable(false);
    btnRefri[13].setClickable(false);
    btnRefri[14].setClickable(false);
    btnRefri[15].setClickable(false);
    btnRefri[16].setClickable(false);
    btnRefri[17].setClickable(false);
    btnRefri[18].setClickable(false);
    btnRefri[19].setClickable(
    PopulaBtnRefri();
    PopulaBtnSobreMesa();

    return rootView;
}
public void PopulaBtnRefri() {
    try {
        gpConn = new GruposProd(getContext());
        Cursor cursor;
        db = gpConn.getReadableDatabase();
        cursor = db.rawQuery("SELECT DISTINCT DESCRICAO_RESUMIDA, CODINTERNOPRODUTO, CODGRUPO FROM PRODUTO_FINAL " +
                "INNER JOIN PRODUTO_ACOMP ON PRODUTO_ACOMP.BEBIDA = 'S' WHERE CODINTERNOPRODUTO = PRODUTO_ACOMP.CODACOMP", null);
        int i = 0;
        if(cursor.getCount() > 0) {
            cursor.moveToFirst();
            do{
                refri[i] = cursor.getString(cursor.getColumnIndex("DESCRICAO_RESUMIDA"));
                btnRefri[i].setText(refri[i]);
                btnRefri[i].setVisibility(View.VISIBLE);
                btnRefri[i].setTextColor(Color.parseColor("#FFFFFF"));
                btnRefri[i].setTextSize(12);
                btnRefri[i].setClickable(true);
                i++;
            }while(cursor.moveToNext());
        }
        db.close();
    } catch (Exception e) {
        Log.e("btnRefri", "erro", e);
    }
}

}
</code>
Comment: Cadê o código chefe?!
Comment: não sei postar ele formatado aqui =(
Comment: Pronto, parte do código ta ai, pelo menos o que é importante
Answer: Em vez de usar:
<code>btnRefri[1].setVisibility(View.INVISIBLE);
</code>
Use:
<code>btnRefri[1].setVisibility(View.GONE);
</code>
Veja essa resposta do Thiago Luiz Domacoski mais detalhes em relação a diferença entre <code>VISIBLE</code>, <code>INVISIBLE</code> e <code>GONE</code>.

View.VISIBLE (Sendo exibido)
View.INVISIBLE (Não é exibido mas ocupa o espaço em tela)
View.GONE (Não é exibido e não ocupa o espaço em tela)

E nessa:

A propriedade Gone faz com que a view seja tratada como se não
  existisse enquanto o Invisible ele simplesmente esta invisível, então
  sim tem diferença.
Comment: Resolveu, muitíssimo obrigado..... Solução simples e direta!!!!! VALEEEEU
Comment: @MarcioVieira se quiser validar a resposta, fique a vontade. =D
Comment: não sei como faz isso kkkkkkkk, até quero
Comment: @MarcioVieira achou até rápido. ehuhe.. boa sorte ai.


Logistic-Regression: Prior correction at test time

Question: Using sklean.linear_model.LogisticRegression for a binary classification problem. My classes are unbalanced. The positive class comprises about 20% of the training set. When fitting the model I use:
<code>logreg = LogisticRegression(class_weight="auto")
logreg.fit(X_trn,y_trn)
</code>
which lets sklearn give greater weight to the infrequent positive class during training. But now I want to re-balance the class_weights for test time. My first intuition is to adjust the logreg.intercept_ member of fitted model. Would this be the correct approach?
Answer: For any distribution with over binary variable $C$ and continuous variable $x$:
\begin{align}
p(C_1|x) &= \frac{p(x|C_1)p(C_1)}{p(x)}\\
&= \frac{p(x|C_1)p(C_1)}{p(x|C_1)p(C_1) + p(x|C_2)p(C_2)}\\
&= \frac{1}{1 + \frac{p(x|C_2)p(C_2)}{p(x|C_1)p(C_1)}}\\
&= \frac{1}{1 + \exp\left(\ln\frac{p(x|C_2)p(C_2)}{p(x|C_1)p(C_1)}\right)}\\
&= \frac{1}{1 + \exp\left(-\ln\frac{p(x|C_1)p(C_1)}{p(x|C_2)p(C_2)}\right)}\\
&= \frac{1}{1 + \exp\left(-w^Tx + b\right)},
\end{align}
where we define $C_1$ as the event where $C=1$ and $C_2$ as the event where $C=0$. Notice this is the typical hypothesis assumed during binary logistic regression. From the above, we have that
\begin{equation}
w^Tx + b = \ln\frac{p(x|C_1)p(C_1)}{p(x|C_2)p(C_2)}= \ln\frac{p(x|C_1)}{p(x|C_2)} + \ln\frac{p(C_1)}{p(C_2)}.
\end{equation}
If, during training, we balance the dataset or weigh the examples inversely to their class prior probabilities, we effectively have that $p(C_1) = p(C_2)$, then the above becomes
\begin{equation}
w^Tx + b = \ln\frac{p(x|C_1)}{p(x|C_2)}.
\end{equation}
The parameters $w$ and $b$ are therefore estimated under the assumption that the class prior probabilities are balanced or equal. We can re-introduce the prior log odds:
\begin{align}
w^Tx + b + \ln\frac{p(C_1)}{p(C_2)} &= \ln\frac{p(x|C_1)}{p(x|C_2)}+\ln\frac{p(C_1)}{p(C_2)}\\
w^Tx + b' &= \ln\frac{p(x|C_1)}{p(x|C_2)}+\ln\frac{p(C_1)}{p(C_2)},
\end{align}
where $b' = b + \ln\frac{p(C_1)}{p(C_2)}$. So by a simple adjustment to the bias term, we can re-introduce unbalanced priors in the test/application setting. A similar argument holds for the case of multi-class logistic regression.


Dimensionality reduction of events data

Question: I have a dataset with different types of user events, and I'd like to set a metric of user activity. I don't have any labeled data of the actual perceived activity level of users.
The data consists of around 10 different types of events (count of events normalized by usage time).
For example:
<code>+---------+--------+--------+--------+--------+--------+
| UserId  | Event1 | Event2 | Event3 | Event4 | Event5 |
+---------+--------+--------+--------+--------+--------+
|   10252 |  0.048 |  1.266 |  0.777 |  1.224 |  0.551 |
|  982850 |  0.000 |  0.000 |  1.085 |  1.356 |  0.526 |
| 1009937 |  0.000 |  0.000 |  0.245 |  0.049 |  0.025 |
| 1029718 |  0.000 |  0.000 |  0.440 |  0.313 |  0.652 |
+---------+--------+--------+--------+--------+--------+
</code>
Looking at the distribution of the events, they all have an exponential-like type of distribution.

Additionally, there's correlation between most of the events. Strongest correlation is around .3
I would like to be able to tell on a scale from 0 to 1, how active a user is, regardless of his/her usage time.
If I were to have only one event, I would fit a distribution to the data and use the probability as the predictor. Because I have multiple events and there's correlation between them, I wonder what would be the best way to model this.
I tried PCA (even though the dada is not normally distributed) and didn't get very promising results (no elbow, 95% of variance is explained by 7 out of 10 PCs).
Any advise would be greatly appreciated!
Answer: As I understand it you are facing a problem of ordering(and then ranking) an unsupervised set of users.
These type of problems can be tackled using a clustering algorithm.
There are many such algorithms (KMeans is pretty common).
Where a general approach would be, cluster all users and rank each cluster based on its centroid.
Since all of your features are on the same scale and have similar distribution, using an euclidean distance in the clustering might work well.
If you need to get more intuition into the 10 variables effect on clustering, you can try using an hierarchical clustering.
This is a great example(python)
Comment: This is actually a good discussion :). Some of the problem is how to combine multiple features(dimensions) into one (ranking). I think a clustering algorithm, which make "most" order in multi dimensional space is a fair first step. One you say k-means(or any other clustering algorithm) bring noise into the decision, it might be cleaning noise.
Comment: Thanks @DaFanat. I also thought of this approach, but the questions is how to decide on the rank of each centroid. Why would clustering help here? I tried hierarchical clustering but it didn't seem (at least visually) very promising.
Comment: Assuming the more activity on all events = more activity over all, you can use the centeroid distance from the origin as a ranking method. If this is not good enough, then maybe using weighting per each event? Do you have any prior knowledge/intuition about the events measured?
Comment: Using the centroid distance from the origin would assume that the distribution is uniform. I'd like to try to maintain the original distribution as much as possible (i.e. the exponential nature of the data)
Comment: Right, the exponential nature is something worth considering. How about transforming(log) the data pre-clustering? Looks like a sound pre-processing step.
Comment: I tried it before PCA, didn't give any better results. I could try this before clustering. I'm just not sure why clustering would help here. One option is to use fit a distribution to each dimension and then sum probability p(X>x) for each new sample. Second option is to run k-means and then calculate the distance from the origin, which is similar to option 1, only that it brings the k-means noise into the decision. Why not stick with the original coordinates of the new sample?
Answer: Your data is nonnegative, so maybe you could try nonnegative matrix factorization?
Also if you think that you can model your data with some kind of distribution coming from exponential family, you could try Generalized Low Rank Models (see Exponential family PCA). They also cover NMF. An example implementation comes from H2O and it is possible to use it from Python and R.

Dimensionality reduction of events data


Reinitialise JScrollPane after AJAX post loading

Question: Im'm loading posts in a div #reviewspostscont, the AJAX code works and the posts are loaded when the scrollbar gets to the end but I can't reinitialise JScrollPane to show them.
I tried different codes but nothing works, this is what i have so far.
Thanks in advance, Matt
<code>jQuery(document).ready(function($) {

$(function()
{
$('#reviewspostscont').each(
    function()
    {

        $(this).jScrollPane(
            {
                horizontalDragMaxWidth : 100
            }
        );
        var api = $(this).data('jsp');
        var throttleTimeout;
        $(window).bind(
            'resize',
            function()
            {
                if (!throttleTimeout) {
                    throttleTimeout = setTimeout(
                        function()
                        {
                            api.reinitialise();
                            throttleTimeout = null;
                        },
                        50
                    );
                }
            }
        );

        $(this).bind(
            'jsp-scroll-x',
            function(event, scrollPositionX, isAtLeft, isAtRight)
            {
            var count = 2;
                if (isAtRight == true) {
        loadArticle(count);
        var api = $(this).data('jsp');
        api.reinitialise();
        count++;
    }

            }
        );

    }
  )

  });

  function loadArticle(pageNumber){
                $.ajax({
                    url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
                    type:'POST',
                    data: "action=infinite_scroll&page_no="+ pageNumber + '&loop_file=loop-reviews',
                    success: function(html){
                        $("#reviewspostscont").append(html);   // This will be the div where our content will be loaded
                    }
                });

            return false;
        }

});
</code>
Answer: You can use autoReinitialise. Here's a demo showing a similar example. And another one. And another.
Comment: Thanks, I had already looked through the website, I can't the api.reinitialise... to work. Now i tried using 'autoReinitialise:true' under the line with 'horizontalDragMaxWidth : 100', but nothing changes and no errors in the console


Anonymous local labels (@@): Which assemblers support multi-step references such as @FF (second-next @@)?

Question: In some x86 assembler dialects, one can place anonymous local labels using @@: and refer to them in jumps like jmp @F where @F refers to "next @@" and @B refers to "previous @@".
Here's a description from Microsoft I found while searching the web: Q33067: Anonymous Labels for Jump Instructions
I implemented support for anonymous local labels in NASM using its preprocessor's macro facilities, in my macro collection. All the way back to the first implementation on 2011-08-08 I had support for multi-step references. That is, jmp @FF refers to the second-next @@.
Today I got curious about the differences, if any, to MASM's handling of anonymous local labels. However, I couldn't find anything explicitly stating that multi-step references are supported by MASM. The link I gave only describes @F and @B. It doesn't specifically state anything to the effect that multi-step references are not supported either, though.
The only occurrence of @FF that I found on the web is in this FASM forum thread which discusses the possibility of adding multi-step @@ references. This seems to imply that, at least prior to this thread, FASM only supported single-step @@ references.
My question is, which assemblers do support multi-step references? Specifically, do MASM and TASM support them?
If you care for the context, I never use @B4 or @F4 except in the macro collection's tests and have as yet used @B3 or @F3 three times:

First @FFF,
the nearby @BBB,
and second @FFF

@B2 and @F2 are fairly common in my sources though.
Comment: I would take the lack of documentation of a feature to mean that it doesn't exist.
Comment: Another source, jump to "Local Code Labels": http://bytepointer.com/masm/ml6.0b_quickhelp.htm Likewise only mentions @F and @B.
Comment: Given that anonymous labels date back to an idea by Knuth and Knuth didn't have "multi-step references," I suppose there won't be many.  If you need so many labels that 0–9 won't cut it, try using a normal label instead.
Answer: GAS numbered local labels (as manual) are the same concept as MASM's @@: can be defined multiple times, f or b suffix to choose the closest one in that direction.
But instead of only @@, you have your choice of any number as the label name (typically single-digit), basically solving the same problem of being able to use labels in macros without hitting multiple-definition problems, and refer to a label that's not the immediately previous or next local label.
    jmp 3f
1:  nop
2:  jmp 4f
3:  jmp 1b
4:

See also ARM Assembly Local Labels for other examples.

NASM doesn't natively have either of these.  .name labels are scoped to the previous non-dot label name, but for use in a macro it has special syntax for macro-local labels like %%foo:.
Comment: I did wonder whether eg `1ff` would be valid, but your manual link makes it explicit that it isn't: "[...] you can only refer to the most recently defined local label of that number (for a backwards reference) or the next definition of a specific local label for a forward reference."
Answer: Instead of leading at-sign @ €ASM uses leading fullstop . to specify localness of the label. Arbitrary number of different local labels can be defined and refered in one namespace block (PROC..ENDP) and they also can be refered from other blocks when the local label is concatenated with the name of its block.
The number of steps (nesting depth) is not limited then, see https://euroassembler.eu/eadoc/#Namespace
Comment: You can't nest in NASM, but the access-from-outside mechanism is *identical*.  After `foo: resb 100` ; `.size equ $ - foo`, you can elsewhere in the program `mov eax, foo.size`.  It's the same concat mechanism you describe, also giving names like `func.loop` in a debugger for a function with a `.loop` local label.
Comment: That's exactly like NASM, except for being scoped to PROC/ENDP instead of just the most recent non-dot label.
Comment: @PeterCordes Yes, but there's another difference: NASM's namespaces cannot be nested, and you cannot jump to a local label in another namespace scope in NASM.


Como esse trecho de código funciona?

Question: Minha dúvida é mais precisamente na linha "8", linha na qual contém o for. Nunca vi um for ser utilizado dessa forma. Eu entendi a lógica da linha, mas o funcionamento dessa iteração me deixou muito curioso.
import csv

%precision 2

with open('mpg.csv') as csvfile:
    mpg = list(csv.DictReader(csvfile))

sum(float(d['cty']) for d in mpg) / len(mpg)

Comment: maneira pythonica de fazer o for em uma só linha, olha outro exemplo básico nesta resposta [aqui](https://pt.stackoverflow.com/questions/192343/o-que-%c3%a9-c%c3%b3digo-pyth%c3%b4nico/192388#192388)
Comment: A estrutura "for" do Python, ao mesmo tempo que é bem robusta, é altamente flexível. E, por isso aceita diversas formas de ser implementada. Esta é uma das maneiras pythonica de se implementar o for em uma só linha. Veja `outros` exemplos [aqui](https://pt.stackoverflow.com/questions/459254/d%c3%a1-para-fazer-o-for-em-1-linha/459263#459263)
Answer: A expressão do tipo
(func(e) for e in seq)

é chamada de expressão de gerador (ou generator expression em inglês). Ela é usada para criar uma sequência pegando os elementos de outra sequência e os modificando - nesse caso, pegando cada elemento e de seq e passando-os pela função func.
Note que o objeto retornado é um tipo de iterável (mais especificamente, um objeto do tipo gerador):
strings = ['1', '2', '3']
nums = (int(s) for s in strings)
print(nums)
# output: <generator object <genexpr> at 0x7f8565e11200>

Os geradores têm algumas propriedades especiais que não vem ao caso agora; resumidamente, você pode iterar sobre eles uma única vez, e para fazer uma nova iteração é necessário recriá-lo, pois ele é "consumido".
A função sum aceita qualquer tipo de iterável, incluindo geradores. Portanto, ao escrever algo como
strings = ['1', '2', '3']
nums = (int(s) for s in strings)
sum(nums)

estou somando todos os elementos dentro do iterável (gerador) nums.
E note também que não preciso necessariamente definir a variável nums. É possível construir o gerador e consumi-lo em uma mesma linha:
strings = ['1', '2', '3']
sum(int(s) for s in strings)

A última minha converte todos os elementos da sequência strings para inteiros e os soma, de uma vez só. Nesse caso não é estritamente necessário utilizar parênteses ao redor da expressão de gerador por uma mera questão de simplificação de sintaxe que Python permite.
Se você fosse tentar replicar esse comportamento com um for loop "tradicional", faria algo do tipo:
strings = ['1', '2', '3']
nums = []
for s in strings:
    n = int(s)
    nums.append(n)
sum(nums)

O que é bem menos prático, na minha opinião. (E não é estritamente equivalente, uma vez que nums agora é uma lista, e não um gerador, mesmo que o resultado final seja idêntico).

Como esse trecho de código funciona?


Missing table error after moving to Hibernate 5.2

Question: After upgrading hibernate to version 5.2.10 i'm getting following error on my Spring Boot (1.4) application:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [abc.DummyPojoClass]
Java class is like:
@Entity
@Table(schema = "abc", name = "DummyPojoClass")
public class DummyPojoClass  {

    @Column(name = "object_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    private Long objectId;

    @Column(name = "name")
    @Value
    private String name;
}

In database table is abc.dummypojoclass, and on Hibernate 4.3 there was no problem with resolving table name. I tried to change naming strategy setting in app.properties this:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

But it didn't help. Any ideas how to solve issue?
Comment: Can you try putting name = "DummyPojoClass" to name = "dummypojoclass" in the @Table annotation
Answer: PhysicalNamingStrategyStandardImpl does nothing. You can extend that strategy and convert table names to lowercase.
public class LowerCasePhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl {

    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
        return context.getIdentifierHelper()
                .toIdentifier(name.getText().toLowerCase());
    }

}

Probably, you will need to change this strategy, if you need something besides a conversion to lowercase.
Comment: So what has changed in Hibernate 5.x, this worked fine with version 4.3?
Comment: @bojek if you didn't use any naming strategy for Hibernate 4 — nothing (except names of constraints).


Why the development of continuous compound growth function divide the rate equally among intervals?

Question: I just read from this article about the relations between continuous compound growth and the mysterious constant $e=2.71818...$.
In that article, it developed that for a growth rate of 100% in a time period, the final continuous growth is:
$$
growth = e = \lim_{n\to\infty}\left(1+\frac{1}{n}\right)^n
$$
I am wondering about the $\frac{1}{n}$ part. It seems the growth rate is evenly divided into $n$ parts.
Why do we have to/can divide it that way? What's the rationale?
ADD 1
There can be many ways to divide the interval of increase. But for a specific number of intervals of $n$, the even approach seems to give the biggest product.
For example, suppose $n=4$. If we divide the increase into 4 separate ones like below:
$$
0.2, 0.2, 0.3, 0.3
$$
no matter how long each interval is, the final outcome can be calculated as:
$$
1.2*1.2*1.3*1.3=2.4336
$$
While the evenly approach gives:
$$
1.25*1.25*1.25*1.25 = 2.44140625
$$
So the even approach is bigger. That is to say, if you want to get the maximum product while keeping the same sum, the evenly division is the way to go. (I remember there's a theorem for this.)
But I still don't know why we have to divide the total increase into each intervals, i.e. why we have to follow $0.2+0.2+0.3+0.3=1$.
Comment: "It seems the growth rate is evenly divided into nn parts." Rather, the author of the post decides to consider the combined effect of a growth of $100\%/n$ over $n$ time periods and they realize that it roughly yields a growth of $e-1$ when $n$ is large. I fail to see much "rationale" in this... (Additionally, their post confuses the growth and the growth plus 1.)
Comment: We do not have to divide it this way, but this seems the most straightforward way to divide it. So if we are to divide our return of 100% in 2 parts (one to be given halfway and another one at the end) then 50% and 50% seems the most straightforward thing to do. It's just the simplest linear relationship between time and return: 1 unit of time returns 100%, 0.5 units of time return 50%. Maybe I did not understand your question. What other partitions do you see as more obvious?
Comment: That article really doesn't help explain things; http://math.stackexchange.com/questions/1831666/compound-interest-why-does-everyone-get-it-wrong.
Comment: @selfawareuser The question you link is concerned with compounding interest (and I think it implicitly confounds compounded and simple interests but that's a different discussion). When the article does the division 1/n, it does not divide compounded interest. This is the nominal **non-compounded** interest of 100%. The article shows what happens when we take this non-compounding interest and we compound it continuously.
Answer: I am still not sure where your question comes from (what is it that confuses you more) but I'll try an answer based on your added information.
You do not have to divide the time interval in equal intervals. It's just one straightforward way to divide it. If you divide it a different way, you will get different answers for finite steps of compounding interest (as you discovered), but you will still get the same answer for the continuously compounded case: $e$. So as long as you take the limit of your process to infinite intervals, the answer will be $e$.
Let's take the limit of your example to infinite intervals. One easy way to do it, is just separate each of your initial intervals $0.2, 0.2, 0.3, 0.3$ in $n$ equal intervals. Notice that the intervals we end up with might have different sizes. For example one interval can be $0.2/n$ while another is $0.3/n$ (the size depends on which was the initial interval we started dividing). Notice what happens when we take the limit for $n \rightarrow \infty$. We can bunch together all infinitesimal intervals that came from the first initial interval of $0.2$. The return of these is $e^{0.2}$. We do this for all of your initial intervals. The total return is:
$$e^{0.2}\times e^{0.2}\times e^{0.3}\times e^{0.3} = e^{0.2+0.2+0.3+0.3} = e$$
The other interesting thing is that you can view this arbitrary division as time intervals that all have proportional rates to the whole time unit rate or you can view it as arbitrary rates for arbitrary intervals. To ease the discussion, let's make the whole time unit to be 1 year and the whole time unit return rate to be 1 (100%). Note also that the rate mentioned here is not compounded. It is the return from your capital only, after one year without compounding (without gaining interest on partial interest). Now consider the following irregular example where for the first month the rate is $0.5$, while for the rest $5$ months it is $0.1$, and the last $6$ months it is $0$. The only limitation is that the time intervals have to add up to 1 year, and the rates have to add up to the total yearly rate of 1. If we calculate the total return assuming continuously compounded interest, it still is $e$.
Now about your last question on why the intervals (or equivalently the rates) have to add up to 1. This is the question that confuses me the most and I do not understand where it comes from. If you have a simple return rate of 100% and you want to break it up, you can do it in any way you want. But adding all the partitions together must total 100% (or whatever your rate is). Otherwise you would have a different return rate.
Say you have one bacterium, and you know that from this bacterium (not its children) you get 4 more bacteria after 4 hours. It does not matter how you get them. It might be that you get 1 each hour, or 3 the first hour and 1 the next 3 hours, or vice versa, but the end result has to be 4 bacteria in 4 hours. If the partial numbers(rates) summed up to something else then you would have a different rate :)
Now let's say that we want to take into account compounded returns (taking into account what the children bacteria produce too) and find the total return after $400$ hours. Since the steps are many we can treat this as a continuously compounded process* and simply say the result is $e^{400}$. It does not matter whether the simple rate of +4 bacteria every 4 hours was uniform within these 4 hours or not. The result is the same.
(*Of course bacteria multiplication is a discrete process, so the steps are finite, and hence the results will differ with different rate profiles, but the more the steps the smaller the difference will be.)
Comment: @smwikipedia I am wondering whether my answer helped with some of your questions around $e$ and continual growth? If you still have questions it might be beneficial to chat in a chatroom so I get a better perspective of what confuses you.


Estimating parameters for a spatial process

Question: I'm given an $n\times n$ grid of positive integer values. These numbers represent an intensity that should correspond to the strength of belief of a person occupying that grid location (a higher value indicating a higher belief). A person will in general have an influence over multiple grid cells.
I believe that the pattern of intensities should "look Gaussian" in that there will be a central location of high intensity, and then the intensities taper off radially in all directions. Specifically, I'd like to model the values as coming from a "scaled Gaussian" with a parameter for the variance and another for the scale factor.
There are two complicating factors:

the absence of a person will not correspond to a zero value, because of background noise and other effects, but the values should be smaller. They can be erratic though, and at a first approximation might be difficult to model as simple Gaussian noise.
The intensity range can vary. For one instance, the values might range between 1 and 10, and in another, between 1 and 100.

I'm looking for an appropriate parameter estimation strategy, or pointers to relevant literature. Pointers to why I'm approaching this problem the wrong way altogether would also be appreciated :). I've been reading about kriging, and Gaussian processes, but that seems like very heavy machinery for my problem.
Comment: What do you mean by a Gaussian with a variance *and* scale parameter? The variance parameter *is* the scale parameter of a Gaussian! I'm also a little unsure about the model you've set up so far. Can you describe the problem you're actually trying to solve in more detail? Using a Gaussian to model low granularity integer-valued observations seems fishy.
Comment: (+1) For an interesting question. Looking forward to understanding what you're trying to solve a bit better.
Comment: Here are several observations: 1. If your values are integer, using Gaussian does not seem appropriate. 2. It is not clear what is the purpose of your model, do you want to identify the clusters of strong belief for example? What will be interpretation of your parameters if you had them? 3. Since you have a grid, why not try to fit mixture of bivariate distributions? Then the grid will be the support of the distribution (say unit square) and the intensities will correspond to high probability regions.
Comment: Thanks all for the interesting points. Let me attempt to clarify. The choice of "Gaussian", in the light of comments, might be a red herring that causes more confusion than it helps. The key feature of the data is the high intensity values at point of highest belief in the location of the person, and the tapering off "radially" around it (which I've observed empirically). The intensity values come from  the solution to a (linear) inverse problem, and so actually don't necessarily need to be integral - that's just the data we happen to have.
Comment: btw I appreciate the attempts to make the question more well defined and better modelled. I'll do my best to explain the actual data setting so as to converge on the right modelling assumptions.
Comment: @Suresh, does each individual get the same amount of influence on neighboring cells (i.e., same variance in Gaussian setting)? What's the density of individuals with respect to grid points? Is influence on neighbors assumed additive?
Comment: Do you know in advance how many people there are? Have you tried looking at k-means?
Comment: @cardinal: it depends. as a first approximation one can assume that each individual influences neighboring cells the same way. the catch comes in at corners, where the effect can be a little skewed. The density is small: a typical image might have 20x20 grid cells and 5 individuals, each having a "footprint" that's significant only over 5x5. Influence can be assumed additive for now. @Sheldon we don't know how many people are there, which is why we are trying to stay away from k-means
Answer: You can use this module of the pysal python library for the spatial data analysis methods I discuss below.
Your description of how each person's attitude is influenced by the attitudes of the people surrounding her can be represented by a spatial autoregressive model (SAR) (also see my simple SAR explanation from this SE answer 2). The simplest approach is to ignore other factors, and estimate the strength of the influence how surrounding people affect one another's attitudes by using the Moran's I statistic.
If you want to assess the importance of other factors while estimating the strength of the influence of surrounding people, a more complex task, then you can estimate the parameters of a regression: $y = bx + rhoWy + e$. See the docs here.(Methods of estimating this type of regression come from the field of spatial econometrics and can get much more sophisticated than the reference I gave.)
Your challenge will be to build a spatial weights matrix ($W$). I think each element $w_{ij}$ of the matrix should be 1 or 0 based on whether the person $i$ is within some distance you feel that it is required to influence the other person $j$.
To get an intuitive idea of the problem, below I illustrate how a spatial autoregressive data generating process (DGP) will make a pattern of values. For the 2 lattices of simulated values the white blocks represent high values and the dark blocks represent low values.
In the first lattice below the grid values have been generated by a normally distributed random process (or Gaussian), where $rho$ is zero.

In the next lattice below the grid values have been generated by a spatial autoregressive process, where $rho$ has been set to something high, say .8.
Comment: That's very interesting (and so is the related Geary C). This might be close to what I need.
Comment: Geary C helps you see how values close to one another cluster, even values in the middle of the distribution. Moran's I helps you see how very high values cluster with very high values, and very low values cluster around very low values. So perhaps you are correct and the simplest and best method is Geary's C. Remember the Geary's C approach is exploratory and will not let you condition your results on other factors. Look at this python module for code to run Geary's C: http://pysal.org/1.1/library/esda/geary.html.
Comment: Let me play with these some more. If it seems to do what I need (and I think it will), this sounds like the best answer.
Answer: Here is a simple idea which might work. As I've said in the comments if you have a grid with intensities why not fit density of bivariate distribution?
Here is the sample graph to illustrate my point:

Each grid point with is displayed as a square, colored according to intensity. Superimposed on the graph is the contour plot of bivariate normal density plot. As you can see the contour lines expand in the direction of decreasing intensity. The center will be controled by the mean of bivariate normal and the spread of the intensity according to covariance matrix.
To get the estimates of mean and covariance matrix simple numerical optimisation can be used, compare the intensities with values of density function using the mean and the covariance matrix as parameters. Minimize to get the estimates.
This is of course strictly speaking not a statistical estimate, but at least it will give you an idea how to proceed further.
Here is the code for reproducing the graph:
<code>require(mvtnorm)
sigma=cbind(c(0.1,0.7*0.1),c(0.7*0.1,0.1))

x<-seq(0,1,by=0.01)
y<-seq(0,1,by=0.01)
z<-outer(x,y,function(x,y)dmvnorm(cbind(x,y),mean=mean,sigma=sigma))

mz<-melt(z)

mz$X1<-(mz$X1-1)/100
mz$X2<-(mz$X2-1)/100

colnames(mz)<-c("x","y","z")

mz$intensity<-round(mz$z*1000)

ggplot(mz, aes(x,y)) + geom_tile(aes(fill = intensity), colour = "white") + scale_fill_gradient(low = "white",     high = "steelblue")+geom_contour(aes(z=z),colour="black")
</code>
Answer: Your model is a two-dimensional random field $X[i,j]$, and you are trying to estimate the joint distribution of the integer-values random variables $X[i,j]$.  You will want to assume spatial stationarity: that is, the joint distribution of $(X[i_1,j_1],...,X[i_m,j_m])$ is the same as the joint distribution of $(X[i_1+k,j_1+l]...,X[i_m+k,j_m+l])$.  In particular, the marginal distribution is the same for every cell. A simple question to ask is the autocorrelation structure of the field.  That is, what is $corr(X[i_1,j_1],X[i_2,j_2])$ given the distance $d([i_1,j_1],[i_2,j_2])$?  We represent this as a function $\rho(d)$.  A simple model for the autocorrelation structure is $\rho(d)=kd^{-1}$, where $k$ is a constant.
A 'gaussian' effect corresponds to a quadratic distance function, but there are many other distance functions you should consider, such as the taxicab norm $d([i_1,j_1],[i_2,j_2]) = |i_1-i_2|+|j_1-j_2|$.  Once you have decided on a distance function and the form of your model for autocorrelation it is simple enough to estimate $\rho(d)$ e.g. via maximum likelihood.  For more ideas, look for "random field".
Comment: @charles  It's an important point: if indeed this apparent trend is to be attributed to autocorrelation, then in principle another independent realization of the process could appear to have a dramatically different trend, such as an increase in value away from a central point.  Because the OP has clearly articulated and distinguished some deterministic elements to the trend (the "radial tapering") and correlational elements ("have influence over multiple grid cells"), a reply that respects this would likely be viewed more positively than one that asserts the OP "will want" to change his mind.
Comment: @charles, the pattern you describe will be present for *each* of grid points, due to spatial stationarity assumption. Stationarity is basically saying that all my points behave similarly. This is not the case described by OP. The answer still is very good, but not appropriate in this case.
Comment: "Want to assume spatial stationarity" appears directly to contradict the OP's assumption that "the intensities taper off radially in all directions."
Comment: How so?  Such a pattern would occur with the autocorrelation structure I proposed.
Comment: I'm not sure I understand the spatial stationarity condition. On the surface, it seems to be at odds with the idea of having a "peak that tapers out" at a specific location, but I'm clearly not understanding something.
Comment: Ah, in that case I would suggest applying "detrending" first and then proceeding with the assumption of stationarity.  Apologies for misunderstanding the problem.
Comment: what is "detrending" ? and please don't apologize :)
Comment: I borrow my terminology from time series analysis.  A simple way to estimate (or remove) a global "trend" in the data is to take local averages, for example: the average value within the radius $d$ neighborhood of each cell.


weighted boolean value - scaling

Question: I am not sure how to implement this, but here is the description:

Take a number as input in between the range 0-10 (0 always returning false, 10 always returning true)
Take the argument which was received as input, and pass into a function, determining at runtime whether the boolean value required will be true or false

Say for example:
Input number 7 -> (7 has a 70% chance of generating a true boolean value) -> pass into function, get the boolean value generated from the function.
This function will be run multiple times - perhaps over 1000 times.
Thanks for the help, I appreciate it.
Comment: What have you tried so far? If you don't know where to begin I'd start with this question: http://stackoverflow.com/questions/9471604/what-is-the-best-way-to-generate-random-numbers
Comment: Use a random number generator.
Comment: I am using a random number generator.
Answer: bool func(int v) {
  float f = rand()*1.0f/RAND_MAX;
  float vv= v / 10.0f;
  return f < vv;
}

Answer: I would say generate a random number representing a percentage (say 1 to 100) then if the random number is less then or equal to the percentage chance mark it as true, else mark it as false.
Answer: Here's an idea , I'm not sure that's it's gonna be helpful;
bool randomChoice(int number){
    int result =rand() % 10;
    return number>=result;

    }

Hope it's helpful
Comment: Ack, **don't** call `srand` every time you call `rand`. Call it **once only**.
Comment: Yeah, reseeding the random number to the current time on every call is a fantastic way to make your numbers not at all random.
Comment: you've got some extra braces there.  Also `if (number>=result) return true; else return false;` is a bit of an anti-pattern.  Just `return (number>=result); `  Oh, and which `random()` function are you calling?  The stdlib one doesn't take an argument http://linux.die.net/man/3/random
Answer: This is an interesting question! Here's what I think you should do, in pseudo code:
boolean[] booleans = new boolean[10]; //boolean array of length 10

function generateBooleans(){
    loop from i = 0 to 10:
        int r = random(10);    //random number between 0 and 9, inclusive
        if(r < i){
            booleans[i] = true;
        }
    }
}

You can then compare the user's input to your boolean array to get the pre-determined boolean value:
boolean isTrue = booleans[userInputNumber]

weighted boolean value - scaling


ExecStartPre and mount command (Linux/Debian)

Question: I have a custom package for service which works fine on Debian10. I want run it on Debian11 or Ubuntu 22 but mount commands in ExecStartPre does not works. Or better they are executed without errors but mount points are not available. When I execute mount commands manually and then start service it looks good. But when server is restarted service cannot start due to missing mount points. Below is small snippet from file:
[Service]
...
ExecStartPre=-mount -o bind,ro /etc/myservice /chroot/%i/etc/myservice.d
ExecStart=/usr/sbin/myservice-%i -n -f /etc/myservice.d/myservice-%i.conf
....

Any idea why mount commands are ignored?
Edit:
It works fine with systemd 245.4-4ubuntu3.18 but when I upgrade to 249.11-0ubuntu3.4 I can't mount anymore. Exit code for commands is "status=0/SUCCESS". Debug mode report more entries than on the previous version of systemd (not sure if logging was extended)
Sep 29 15:44:48 myhostname systemd[18647]: Bind-mounting / on /run/systemd/unit-root (MS_BIND|MS_REC "")...
Sep 29 15:44:48 myhostname systemd[18647]: Applying namespace mount on /run/systemd/unit-root/run/credentials
Sep 29 15:44:48 myhostname systemd[18647]: Successfully unmounted /run/systemd/unit-root/run/credentials/systemd-sysusers.service
Sep 29 15:44:48 myhostname systemd[18647]: Bind-mounting /run/systemd/inaccessible/dir on /run/systemd/unit-root/run/credentials (MS_BIND|MS_REC "")...
Sep 29 15:44:48 myhostname systemd[18647]: Successfully mounted /run/systemd/inaccessible/dir to /run/systemd/unit-root/run/credentials
Sep 29 15:44:48 myhostname systemd[18647]: Applying namespace mount on /run/systemd/unit-root/run/systemd/incoming
Sep 29 15:44:48 myhostname systemd[18647]: Followed source symlinks /run/systemd/propagate/myservice → /run/systemd/propagate/myservice.
Sep 29 15:44:48 myhostname systemd[18647]: Bind-mounting /run/systemd/propagate/myservice on /run/systemd/unit-root/run/systemd/incoming (MS_BIND "")...
Sep 29 15:44:48 myhostname systemd[18647]: Successfully mounted /run/systemd/propagate/myservice to /run/systemd/unit-root/run/systemd/incoming
Sep 29 15:44:48 myhostname systemd[18647]: Remounted /run/systemd/unit-root/run/credentials.
Sep 29 15:44:48 myhostname systemd[18647]: Remounted /run/systemd/unit-root/run/systemd/incoming.
Sep 29 15:44:48 myhostname systemd[18647]: Remounted /run/systemd/unit-root/run/credentials

Basic folder structure is created with jailtool what is old package but I tried same with jailkit with same result.
Start/restart/stop of service was done with root user.
Answer: At the end I had to define MountAPIVFS to false to be able see mount points.
Answer: What status or error code of the mount command do you see in the output of systemctl status for this service?
Does your service switch to a different user, so that the mount command does not run with the required (root?) privileges? In this case you can prefix your ExecStartPre command with an "+" sign, like this:
ExecStartPre=+/sbin/mount -o bind,ro /etc/myservice /chroot/%i/etc/myservice.d