Change appearance of search form

Question: I want to change the appearance of the Drupal 7 search form.  I used this code in my preprocess-html.inc file for my Omega subtheme.  It didn't work.  How do I assign html classes to divs within the Drupal 7 preprocess-html.inc file?
Here's what I put in that didn't work:

<?php

function mythemename_form_search_block_form_alter(&$variables) {
  // custom functionality here

}

?>

            <input type="text" class="form-control" placeholder="Search for...">

            <button class="btn btn-default" type="button">Go!</button>

To clarify, how do I add this bootstrap html code to the template file? I need to add these classes to the search form.
Comment: To clarify, how do I add this bootstrap html code to the template file?  I need to add these classes to the search form.
Answer: To design the search block form you can override the existing search-block-form.tpl.php in the theme's template folder.
<?php

$variables['form']['search_block_form']['#attributes']['placeholder'] = "Search for...";
$variables['form']['search_block_form']['#attributes']['class'] = "form-control";

?>

        <?php if (empty($variables['form']['#block']->subject)): ?>
          <button class="btn btn-default" type="button"><?php print t('Go!');?></button>
        <?php endif; ?>
        <?php print $search_form; ?>

Comment: I keep getting a syntax error.  I put  and  tags around the whole thing as before, and put your code inside the function, replacing what I had.  What am i doing wrong? Thanks for your help, too :)
Comment: Don't add  and  tag. Directly add the code and proper open and close the php tag. On which line you get the error ?
Comment: I get the error on the line of the first .  The error was on , and then when I deleted those divs, it went to the <div class="col-md-3" line.
Comment: Please ensure that PHP code is correctly enclosed within the PHP tags.

Change appearance of search form


What is parameter instability? How can I measure it?

Question: What is parameter instability and how can I measure it?
If my model is having a hard time to forecast out-of-time samples, could parameter instability or populational instability be the cause of it?
Comment: This is a good question, but may be hard to answer. I suspect you will find that different people will use these terms in different ways. Can you provide some context? Where did you see these terms used, eg?
Answer: I agree with @gung there are some terminology or definition issues needs to be clarified.
What you described "hard time to forecast out-of-time samples" can be viewed as a "overfitting" problem in machine learning literature. For example, if we fit a very complex model on small amount of data, it is very likely the model "overfit" the data given, and fail to generalize to out of time samples.
Here are a widely used examples for overfitting (from wikipedia). You can see the model is trying too hard to fit the given data perfectly. Because the data contains noise, the model is not really generalizable to out of time sample.

To measure if the model is overfitting, bais and variance of the model can be calculated. For OLS, an example can find here. Intuitive explanation of the bias-variance tradeoff?

In fact, the first thing comes to my mind by reading the question title is numerical stability. This means because computer can only process finite digits numbers, there are algorithms that work theoretically but not working in real world.
Comment: This is possible, but the question is vague, IMO. My suspicion (but it's really only a guess) is that the "parameter instability" is that the relationship / parameter values are changing over time, such that the original fit could have been fine, but future accuracy will be poor nonetheless. Likewise, "population instability" might be that the model is learned on 1 population (say, grumpy old men), but subsequently applied to a different population (say, young whipper-snappers). Or they might be something else entirely...


Profile2 Template for edit page

Question: i already searched all relevant drupal sites - but without success.
I have to create a own template file for the "edit user profile" site of the module Profile2.
As far as i know, i have to hook the new templatefile in the template.php of my theme - but what keywords and syntax do i need to accomplish that?
Every hint would be great!
Thanks.
Answer: I did this way to create my own "edit user profile" for profiles of profile2 module.
function customtheme_theme() {
    $items = array();
    $items['user_profile_form'] = array(
        'render element' => 'form',
        'path' => drupal_get_path('theme', 'customtheme') . '/templates',
        'template' => 'user-profile-form',
        'preprocess functions' => array(
             'customtheme_preprocess_user_profile_form'
        ),
    );
    return $items;
}

I put customtheme_theme() function into my template.php file of customtheme theme. (a custom theme that i used for my website)
After that i created the template file user-profile-form.tpl.php and placed in the templates folder of my theme.
The customtheme_preprocess_user_profile_form function you can use that for changing some variables before render the profile form or if you dont need any changes you can remove the preprocess_functions.
After add the customtheme_theme(), create user-profile-form.tpl.php template. You have to clear cache and you can see the layout change for user-profile-form.
Answer: Thanks for this very detailed reply.
I made all entrys in the template.php and user-profile-form.tpl.php and cleared all cache multiple times.
Unfortunately the edit site does not change.
Iam confused about the $items['user_profile_form'] keyword - is there any reference, because in other forums i read something about $items['user_profile2_edit']?
I keep on trying and will reply as soon as it works! Thx
Comment: So you are asking about separate tpl file for **profile2** profile edit page ?
Comment: Exactly! I guess Stone Vos answer should work ... but iam still searching the reason why the new tpl file doesnt show up.
Comment: Have you checked this question: http://drupal.stackexchange.com/questions/31203/theme-the-user-edit-profile-page
Comment: Hm, i checked it out, but the self-answered question is about another module. Approach 2 is very similar to Stone Vos reply and i cant detect any significant differences :/
Comment: Did you solve the problem?
Comment: Thanks for the reminder. Kinda bussy the last weeks and havent made any progress on this topic. Iam still wondering, if the $items['user_profile_form'] = array(
... is the correct keyword. I changed the user-register template successfully with the hook 'user_register_form', so iam sure the template file is parsed correctly.
Comment: to be more precisely: for my understanding the hook should be something linke 'user_profile2_edit' or similar ... is there any reference?!
Answer: This is how I accomplished different template files for each Profile2 Edit Page.
First, form_alter to set up the form #theme properly
function THEME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_profile_form') {
    if ($form['#user_category'] === 'writers') {
      $form['#theme'] = 'profile2_writers_edit_form';
    } else if ($form['#user_category'] === 'secondary') {
      $form['#theme'] = 'profile2_secondary_edit_form';
    } else if ($form['#user_category'] === 'main') {
      $form['#theme'] = 'profile2_main_edit_form';
    }
  }
}

Then you can set up the templates this way
function THEME_theme() {
  return array(
    'profile2_writers_edit_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'template' => 'profile2-writers-edit',
      'render element' => 'form',
    ),
    'profile2_secondary_edit_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'template' => 'profile2-secondary-edit',
      'render element' => 'form'
    ),
    'profile2_main_edit_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'template' => 'profile2-main-edit',
      'render element' => 'form',
    ),
  );
}

Now all you have to do is add the files to your theme folder and clear cache. In this case I ended up with the following files for Profile2
profile2-writers-edit.tpl.php
profile2-secondary-edit.tpl.php
profile2-main-edit.tpl.php

A basic tpl should look something like this

  <?php print drupal_render_children($form); ?>
  <?php print drupal_render($form['#submit']); ?>

Print fields singularly like so
<?php print drupal_render($form['FIELD_NAME']); ?>

Comment: This is a good example IMO. I have been trying to work out how I need to set up 3 custom Edit pages for 3 member types. Your example makes good sense and explains what to do by example. You should put your example on the drupal.org site as no other clear concise examples show how to add 'more than 1' profile2 edit page. Thanks for the effort & time amigo.

Profile2 Template for edit page


2 different sheets with their own data source

Question: In Tableau Desktop, does anyone know how to switch between 2 data sources in 2 different work sheets?
I created 2 data sources and 2 sheets.
But if I try to assign one sheet a different data source, it changes it for both.
Is there a trick to doing this?
Answer: All you need to do is click on the data source you want to use on the sheet and add a field from that data source to the sheet. If you don't add a field to the sheet, it doesn't keep the association to that selected data source.
So, for example, say you have 2 data sources in the data source pane. Go to Sheet 1. Click on data source 1. It will display the fields from that data source in the Tables pane.

Add one of the fields from data source 1 to Sheet 1. This associates that sheet with data source 1.
Then go to Sheet 2. By default, it's showing the fields from data source 1. To change it to data source 2, just click on that second data source.

Then add a field from data source 2 to Sheet 2. Sheet 2 is now using data source 2.
If you go back to Sheet 1, you'll see it's still using data source 1.


Mclust: Data frame order affects solution

Question: I've come across some behavior in mclust::Mclust that I would not have expected, which is that the order of variables in the data passed to Mclust affects the solution it comes up with.
In the example below, the first ordering of the variables produces 2 profiles, and the second produces 6. However, calling either of these orders does produce a stable solution (e.g., the first call to Mclust will always produce 2 profiles).
> testData <- read.file(f = "http://fimi.ua.ac.be/data/chess.dat")

> summary(Mclust(subset(testData, select = c(X1, X3, X5, X7, X9, X11))))
----------------------------------------------------
Gaussian finite mixture model fitted by EM algorithm
----------------------------------------------------

Mclust EEV (ellipsoidal, equal volume and shape) model with 2 components:

 log.likelihood    n df      BIC      ICL
       3547.068 3195 49 6698.738 6692.126

Clustering table:
   1    2
2759  436

> summary(Mclust(subset(testData, select = c(X11, X9, X1, X3, X5, X7))))
----------------------------------------------------
Gaussian finite mixture model fitted by EM algorithm
----------------------------------------------------

Mclust EEV (ellipsoidal, equal volume and shape) model with 6 components:

 log.likelihood    n  df      BIC      ICL
       18473.94 3195 137 35842.37 35834.51

Clustering table:
  1   2   3   4   5   6
431 932 210 881 524 217

My suspicion is that the initialization step (that the documentation suggests is a hierarchical clustering procedure) is affected by the order of variable passed, but I'm not sure if there's a straightforward way to overcome this.
Update: It appears that there is something to my suspicion that the initialization step is involved in this behavior. If I load the same dataset as above, but instead pass Mclust an hcPairs list to its initialization argument that's based on an EII model, I get stable results across variable orders:
> testData <- read.file(f = "http://fimi.ua.ac.be/data/chess.dat")

> hc <- hc(subset(testData, select = c(X1, X3, X5, X7, X9, X11)), modelName = "EII")
> summary(Mclust(subset(testData, select = c(X1, X3, X5, X7, X9, X11)), initialization=list(hcPairs = hc)))
----------------------------------------------------
Gaussian finite mixture model fitted by EM algorithm
----------------------------------------------------

Mclust VEV (ellipsoidal, equal shape) model with 2 components:

 log.likelihood    n df      BIC      ICL
       3391.936 3195 50 6380.405 6380.254

Clustering table:
   1    2
1386 1809
> summary(Mclust(subset(testData, select = c(X11, X9, X1, X3, X5, X7)), initialization=list(hcPairs = hc)))
----------------------------------------------------
Gaussian finite mixture model fitted by EM algorithm
----------------------------------------------------

Mclust VEV (ellipsoidal, equal shape) model with 2 components:

 log.likelihood    n df      BIC      ICL
       3391.936 3195 50 6380.405 6380.254

Clustering table:
   1    2
1386 1809

Interestingly, this doesn't match either of the first two cluster/profile solutions above (the ns for the two-profile solution above don't match). I also don't have a clear understanding of why an EII model in the hc step produces these effects, I simply tried all possible models in the hc step and EII was the only one that produced these stable solutions.
Can anyone confirm that this is a sound way to go about this type of profile analysis, or offer an alternate solution?
Comment: Interesting. The second result is also very different in quality. Have you verified it is the initialization? How do results compare to other EM results such as with ELKI's EM? What if you fix the cluster number to 2/6?
Comment: @Anony-Mousse I updated the question above to include more information on the initialization step. If I fix the number of factors at 2 in my original example, the first analysis (X1, X3, X5...) produces the same solution. The second analysis (X11, X9, X1...) produces a 2-profile solution, but it doesn't match the first analysis.
Comment: So, does hc yield different results then?
Comment: In comparing the `hc` call that mClust would normally do that resulted in different output, the `hc` output seems the same:
hc1 <- hc(subset(testData, select = c(X1, X3, X5, X7, X9, X11)))
hc2 <- hc(subset(testData, select = c(X11, X9, X1, X3, X5, X7)))
hc1 %in% hc2
Comment: Have you tried setting a seed?
Answer: You may try SVD transformation described in Scrucca and Raftery (2015).
In this paper they pointed out the order of variables of your input data may affect your initial output of hc algorithm.
Mclust package does offer such options. Just like
mod <- Mclust(X, initialization = list(hcPairs = hc(X, use = "SVD")))


how to listen to user camera event all the time

Question: I have been writing a Dropbox like android app, which automatically upload photos to the server. When user take photos by camera and save them on SD Card, it will be noticed to upload these photos.
I started a service to ensure long time listening, and registered a Content Observer to listen camera event. But when OS under resource pressure, it will kill the service and the Content Observer wont be fire any more. So how to make the Content Observer always working?
BTW, the point of my question is asking how to keep Content Observer running as long as possible just like service does. And if Content Observer is not the best option what else is.
Comment: I think you will have to crate a [BroadCastReceiver](http://www.vogella.com/tutorials/AndroidBroadcastReceiver/article.html) for the `Intent.ACTION_MEDIA_SCANNER_SCAN_FILE` intent
Comment: but I think it doesn`t gurantee instantly process
Comment: okay then if you cant you can listen to [ACTION_IMAGE_CAPTURE](http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE)
Comment: Can you re-execute same code in onChange()
Comment: @SagarPilkhwal actually I followed by this tutorial:http://www.jessechen.net/blog/how-does-google-plus-instant-upload-work/
Comment: BTW, the point of my question is asking how to keep Content Observer running as long as possible just like service does. And if Content Observer is not the best option what else is.
Comment: @SagarPilkhwal listen to ACTION_IMAGE_CAPTURE does`t guarantee the camera event is exact photo taking event, it could be photo modification or something else. Here I only need to catch photo taking event
Comment: i guess you will have to create some logic when `ACTION_IMAGE_CAPTURE` intnet is triggered and a new image file is added to the gallery
Answer: Try this but it has some limitations:
<receiver android:name=".pictureReceiver" >
        <intent-filter android:priority="10000" >
            <action android:name="android.intent.action.CAMERA_BUTTON" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</receiver>

BroadcastReceiver implemented that's currently listening for "android.intent.action.CAMERA_BUTTON". However, this doesn't seem to get called when wanting it to. It only gets broadcast if the foreground activity does not consume the event.
OR
You can use FileObserver:
new FileObserver(path) {
@Override
public void onEvent(int event, String path) {
    if (event == FileObserver.CREATE)
        Toast.makeText(getActivity(), "File created", Toast.LENGTH_SHORT).show();
    }
}.startWatching();

Tutorial Link
Comment: I noticed this solution before, and also tried ContentObserver proposal, both don`t meet my requirement. I need to keep it listening camera event all the time, and when a photo was taken upload it instantly.
Comment: you can use FileObserever
Comment: tutorial link seems to be broken


30+ small modules versus 5 large modules versus 1 HUGE module: Which is better?

Question: So, we have a large, complex Drupal 6 site, which has lots of secret sauce and magic glue making it work.
Where we can, we've contributed modules back and made them generic, but we still have 30 or so custom modules to keep it working the way we need it to. Each module (in most cases) has a specific function e.g. our hook alters for the notification system.
We are doing a huge code review at the moment and looking at improvements we can make. One thing suggested is to merge the large number of modules into a few smaller master modules, with lots of include files. We would, perhaps group by general site area e.g. "community", "admin" and "messaging", instead of specific modules per functionality.

Is the effort in doing this worth it? Will it speed up the site?
What module grouping would you recommend?

by site area ("community", "admin", "upload")
by hook ("form", "node", "user", "theme")
everything in one module
something else?

What naming conventions should we use for the include files to keep the codebase sane?
Am i right in assuming the goal should be tiny .module file with includes per hook / menu / area?
Comment: Should we mark this CW?
Answer: It sounds like you don't really know what your bottleneck is. This restructuring will likely have very little impact on performance (unless you happen to find and trim some major bloat in the process), but it may make things easier for you to maintain. If you do decide to restructure I would recommend splitting up along "site features" (blog, image galleries, etc.).
But if performance is your concern you first have to diagnose the problem before you attempt surgery.
Comment: Performance was the wrong think to ask about. Its more about best practice than shaving nano-seconds.
Answer: Modules should do one thing, and one thing well.  The "thing" should be a piece of functionality on the site.  That module should include all of the hooks to do that one thing.  As much as possible, disabling a module should have limited side effects on the site, and should be limited to just disabling the "thing".
Ask yourself:
Can I have multiple hands in the project with how I am splitting / combining modules?
If I need to change the module a year from now, am I going to have an easy time honing in on where things are implemented?
If I need to edit some code, am I going to have to be worried about mucking up another feature (think shared hooks like form_alter, block_view, etc)?
I always choose ease of maintainability over minute performance impacts on a site.
Comment: We went down that route and ended up with 30+ custom modules. The defintion of "thing" is quite vage, it could be "customise ubercart emails" (small module) or "send emails to users" (large) or "control email communications" (huge, includes notifications customisations, ubercart, signup, password reminders etc).  The question really is how to define the "thing" to split with :).
Comment: If you disable ubercart, would you need to edit a monster module?  I would rather have 100 modules that can be enabled/disabled easily w/o dependency hell.  If would also have 100 modules if it means that I can find exactly what I am looking for a year later without having to wade though a monster module.
Answer: You'll need to carry out performance testing to answer the question of if it will speed up the site. Search for Mark Sonnabaum's recent XHProf presentation, as this is a painless way to do so.
Another approach beyond the ones suggested that you could take is seeing if you can now re-implement any of your custom code using contributed modules. Rules, Views, and other contributed modules have probably come a ways since you first wrote your code, so this could be another way to simplify, although you will likely end up exporting those configurations again with Features anyway :) - still, at least it'll be a bit less code/configuration for you to maintain in the end if that's one of your goals.
Answer: Using the Drupal core code as example, each module should implement independent functionalities. For example, in Drupal, the module for handling the taxonomy term is the Taxonomy module; it is not the Node module that include that functionality in its code.
The question is then, when do you split a module in two, and when do you keep the code in the same module?

If the code that should go in the new module is just few lines, then the code should be kept in the old module.
If in the old module you keep writing in different hooks is similar to if ($option_enabled) { /**/ }, then the code should be written in a new module; in this way, instead of having a module that tests if the functionality has been enabled, the administrator users enable the new module if they want the functionality.

Keep in mind that, when you split code in two modules, the main module should not depend from the secondary module, but vice versa. This means the main module should not verify the secondary module is enabled before to execute some code; if this happens, you should consider re-write the code to use a hook that is then implemented from the secondary module.
Between the following snippets, the second is preferable.
if (module_exists('secondary_module')) {
  // Code that requires the secondary module.
}

// Invokes the hook that is implemented by the secondary module.
module_invoke_all('hook_name');


Pros and cons of using Windows containers instead of Linux containers for Docker?

Question: I'm installing Docker for Windows (CE) on Windows 10 and the first screen asks me:

[  ] Use Windows containers instead of Linux containers (this can be changed after installation)

This seems an important decision, yet the Docker documentation, FAQ and Windows container tutorial provides no information about why I might choose one over the other.
It would be helpful to have an objective overview of the ramifications of this choice:

Will one option be faster than the other?
Does the decision affect usage of system resources (RAM, CPU)?
Can I run the same images on both types?
Is one more secure than the other?

Any other distinctions that might help me reach a conclusion would be very welcome.
Comment: The answer to this is not opinion based. And it is accepted. So no need to close this one.
Comment: I think that a better answer to what the OP really wanted to know (although possibly didn't ask it so precisely) is here: https://stackoverflow.com/a/48080376/261332, or here: https://stackoverflow.com/a/48080526/261332 (they are both in the same question)
Answer: You HAVE to use a windows host for windows containers, however you can use either a Linux host or a Windows host for Linux containers. Since April 2018 you can even run both in parallel.

Will one option be faster than the other?

No. faster at what?

Does the decision affect usage of system resources (RAM, CPU)?

Windows uses more resources than Linux - Windows Nano is as small as it gets

Can I run the same images on both types?

No. you can run .NET apps in mono containers but you cannot start a windows container on a Linux host and vice versa - it's not the same as virtualization

Is one more secure than the other?

Again - more secure at what? No.
They both run native Docker so it's nothing like hyper-v vs VMware and more like Linux vs Windows so it all depends on what you are going to run .net, python, java, ruby etc.
Comment: So if I select to use Linux containers, Docker will fire up a Hyper-V Linux VM to run my containers, otherwise it will run Windows containers natively? And I can't run both types of container concurrently?
Comment: Second this. The read complement this answer https://containerjournal.com/2016/10/28/linux-vs-windows-containers-whats-difference/
Comment: @DuncanJones, just 3 days after you asked there was a [blog post](https://blogs.msdn.microsoft.com/premier_developer/2018/04/20/running-docker-windows-and-linux-containers-simultaneously/) on MSDN explaining that you now CAN run Windows and Linux containers in parallel.
Comment: docker for windows 10 allows you to do this - but in production you would have a docker swarm with Linux and Windows hosts
Comment: @Sum1sAdmin put that in the answer
Comment: Docker is based on lxc (Linux) - it will use the same kernel as the Docker-host. If you start windows in a lxc it has to virtualize or emulate win. Not sure if the same applies to win-docker, since win supports linux.
Comment: This answer doesn't clear much up for me. Do Windows containers also run in separate Hyper-V VMs? Is it as simple as "windows images require windows containers, linux images require linux containers"?
Comment: yes they 'also' run in lightweight hyper-v vms. but, their natural design is a chroot environment which is isolated or 'contained' but using the same kernel, e.g. not running in it's own OS with hardware emulation, i.e. virtualization. Microsoft now offer 'process isolated' containers which share the same kernel as the host and do not require a separate virtual machine - as to the requirements - it's kernel fork and chroot'ed environment essentially, so the requirements of the host are a running Windows/Linux kernel, you can't fork a Linux kernel and run Windows and vice versa :-)
Comment: @OrangeDog - That wasn't the question


Unequal sample sizes in 2x2 between-subjects ANOVA

Question: I have a 2x2 between-subjects design consisting of Gender (Male, Female), and Relationship status (Married, Single). The DV is completion of a certain behaviour (Yes, No). I plan to use SPSS. I plan to do a factorial ANOVA on this design and then I also have one scale (which I will use to complete separate mediation analyses).
I have 4 different sample sizes in my 4 cells (24, 28, 24, 27).
I would like to ask whether I need to do something differently when conducting my factorial ANOVA?
I have checked google (and this site), some say ANOVA can deal with unequal sample sizes and nothing needs to be done and then there are some youtube videos showing otherwise (it's not always clear and it mostly considers one-way ANOVAs).
Thank you so much to whoever answers my query.
Answer:
The DV is completion of a certain behaviour (Yes, No).

Then you should not be doing ANOVA. That's appropriate for continuous outcomes, not binary outcomes like yours. See this web page for guidance on how to choose a statistical test based on the nature of the outcome and predictor variables.
You should do a binary regression, with logistic regression being the typical version. You would model the log-odds of a Yes response as a function of your Gender and Relationship predictors, and include an interaction term between them. You don't need to worry about the different numbers in each group, as the errors around the group estimates are assumed to be based on binomial statistics rather than a Gaussian distribution.*
This UCLA web page shows how to implement logistic regression in SPSS.

*Even if you were doing ANOVA with a continuous outcome, the sample sizes are so close that you wouldn't have to worry. ANOVA is now typically implemented via regression models with interaction terms, analogously to how you will do your logistic regression. The main issue even in classic ANOVA isn't the equality of sample size per se. It's that without (approximately) equal sample sizes you might get into trouble if the variances within each group aren't the same. Quality control of a regression model includes evaluating how well the equal-variance assumption holds.
Comment: You seem to be absolutely right. It's just that the design seemed so ANOVAy minus the yes/no DV (outcome). We learned that regression is done when we want to know whether independent variables predict an outcome variable. I want to know the differences between different groups and conditions (male vs female and married vs single) in affecting a DV (helping behaviour). We hypothesise that those in the married condition and who are women are more likely to help than those who are men and are in the single condition. Thank you so much for the resources and taking the time to respond.


Non-accumulation points are spaced apart

Question: Let $(X,d)$ be a separable metric space and $A\subset X$ is an infinite uncountable set.  $x \in X$ is said to be the accumulation point of $A$ if $\forall \varepsilon>0$ $B(x, \varepsilon) \cap A \backslash\{x\} \neq \emptyset$.  Let's define $A_0=\{x \in A \mid\exists \epsilon>0, B(x, \epsilon) \cap A=\{x\}\}$.  Prove that, for all $x,y \in A_0$ with $x\not=y$, there exist $\epsilon_x,\epsilon_y>0$ such that
$$
 B\left(x, \epsilon_x\right) \cap B\left(y, \epsilon_y\right)=\emptyset
 $$
I tried to use the contradiction to be able to use the argument that $x,y\in A_0$ but I can't get the intersection to be empty.  Since $x\not= y$ I thought of using this idea to show that the balls are disjoint, since the balls associated to these points give the same point when they intersect $A$, but it is in particular $A$ that does not allow me to work directly with the balls, so I don't know how to continue.  I would appreciate some help.
Comment: Isn't $\varepsilon_x = \varepsilon_y = \frac{1}{4}d(x,y)$ always working independently of $x,y$ being in $A_0$ or not? I suspect that there is a typo and that $\varepsilon_x$ must be found independently of any $y\in A_0$.
Comment: For each accumulation point, take an $\epsilon$ given by the definition, and halve it.
Comment: @DavidHartley but I need to work with the non-accumulation points, and you are telling me to use the accumulation points. In any case, following what you suggest, I cannot conclude what is requested.
Comment: Sorry, I meant non-accumulation point. I.e for each $x \in A_0$ choose an $\epsilon_x$ such that $B(x, 2\epsilon_x) \cap A=\{x\}$.
Comment: @DavidHartley of course, following these steps, my idea is to follow through contradiction. Taking $z\in B(x,\epsilon_x)\cap B(y,\epsilon)$ I have that $z\in B(x,2\epsilon_x)$ and $z\in B(y,2\epsilon_y)$, so if I manage to show that $z\in A$, I will have the contradiction that I expect, however this is where I get stuck. Am I on the right track?
Comment: @Didier: Now that you mention it, obtaining disjoint open balls is rather trivial -- every metric space is a $T_2$ space, and open balls form a basis for the topology. I wonder whether my carefully written and proofread proof is simply a horrendously complicated way of proving something obvious with no redeeming aspects, or whether it can be tweaked to prove what the OP intended. I'm not all that interested in investigating this now, but if the OP posts a corrected statement of what is intended, I'll look into this at a later time (probably tomorrow, if a correction is made before then).
Answer: Expanding on the hint given by @David Hartley:
Let $x$ and $y$ be different elements of $A_0.$ Choose $\epsilon'_x > 0$ and $\epsilon'_y > 0$ so that $B(x, \epsilon'_x) \cap A=\{x\}$ and $B(y, \epsilon'_y) \cap A=\{y\}.$ Let $\epsilon_x = \frac{1}{2}\epsilon'_x$ and $\epsilon_y = \frac{1}{2}\epsilon'_y.$ To show that $B\left(x, \epsilon_x\right) \cap B\left(y, \epsilon_y\right)=\emptyset,$ assume for a later contradiction that there exists $z$ such that $z \in B\left(x, \epsilon_x\right) \cap B\left(y, \epsilon_y\right).$ Since $z \in B\left(x, \epsilon_x\right),$ we have $d(x,z) < \epsilon_x = \frac{1}{2}\epsilon'_x.$ Since $z \in B\left(y, \epsilon_y\right),$ we have $d(z,y) < \epsilon_y = \frac{1}{2}\epsilon'_y.$
Using the triangle inequality, we have
$$d(x,y) \;\; \leq \;\; d(x,z) \; + \; d(z,y) \;\; < \;\; \frac{1}{2}\epsilon'_x \; + \; \frac{1}{2}\epsilon'_y$$
At this point it will help to introduce the positive number $\max \{\epsilon'_x, \, \epsilon'_y \},$ which is greater than or equal to each of $\epsilon'_x$ and $\epsilon'_y.$
From the last inequality and $\;\epsilon'_x \leq \max \{\epsilon'_x, \, \epsilon'_y \}\;$ and $\;\epsilon'_y \leq \max \{\epsilon'_x, \, \epsilon'_y \},\;$ we have
$$ d(x,y) \;\; < \;\; \frac{1}{2}\epsilon'_x \; + \; \frac{1}{2}\epsilon'_y \;\; \leq \;\; \frac{1}{2}\max\{\epsilon'_x,\,\epsilon'_y\} \; + \; \frac{1}{2}\max \{\epsilon'_x,\,\epsilon'_y \} \;\; = \;\; \max\{\epsilon'_x,\,\epsilon'_y\}$$
We now consider two exhaustive cases, which however are not necessarily distinct (because $\epsilon'_x = \epsilon'_y$ is possible).
Case 1: $\;\;\underline{\max\{\epsilon'_x,\,\epsilon'_y\} = \epsilon'_x.}$ From $d(x,y) < \max\{\epsilon'_x,\,\epsilon'_y\}$ we have $d(x,y) < \epsilon'_x,$ and hence since we also have $y \in A_0 \subseteq A,$ it follows that $y \in B(x,\epsilon'_x) \cap A.$ However, this contradicts $x \neq y$ and $B(x, \epsilon'_x) \cap A=\{x\}.$
Case 2: $\;\;\underline{\max\{\epsilon'_x,\,\epsilon'_y\} = \epsilon'_y.}$ From $d(x,y) < \max\{\epsilon'_x,\,\epsilon'_y\}$ we have $d(x,y) < \epsilon'_y,$ and hence since we also have $x \in A_0 \subseteq A,$ it follows that $x \in B(y,\epsilon'_y) \cap A.$ However, this contradicts $x \neq y$ and $B(y, \epsilon'_y) \cap A=\{y\}.$
After thought: I don't seem to have used the hypotheses that $X$ is separable or that $A$ is uncountable.
Comment: Thank you very much! Another question i have is how can i check that $A_0$ is countable.  Any hint?
Comment: Consider the After Thought in Dave Renfro's answer.


Como eu crio um loop que permita cancelar a ordem anterior quando passar de um certo valor?

Question: Boa noite. A seguinte linguagem é MQL5. Estou a criar um robô para o MetaTrader 5. Eu criei depois de muitas horas o código que aparecer a seguir. Eu na altura fiz os comentários em inglês tal e qual como no tutorial pois o vídeo estava em inglês. O meu objetivo é fazer com que uma ordem BUY seja criada sempre que o valor de RSI(Relative Strenght Index) passe a ser maior que 70, e mal passe a ser menor que 70, que crie uma ordem SELL, deletando a ordem anterior. Como a estratégia vai sempre responder aos valores de RSI, ela não precisa de Stop Loss ou Take Profit. Tem algumas coisas que não sei o que fazem ou se realmente são necessárias. Eu gostava de saber o que fiz errado.
Obrigado a quem poder ajudar.
<code>//+------------------------------------------------------------------+
//|                                                     RSIrobot.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\Signal\SignalRSI.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingNone.mqh>
//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string             Expert_Title         ="RSIrobot";  // Document name
ulong                    Expert_MagicNumber   =18801;       //
bool                     Expert_EveryTick     =false;       //
//--- inputs for main signal
input int                Signal_ThresholdOpen =10;          // Signal threshold value to open    [0...100]
input int                Signal_ThresholdClose=10;          // Signal threshold value to close [0...100]
input double             Signal_PriceLevel    =0.0;         // Price level to execute a deal
input double             Signal_StopLevel     =50.0;        // Stop Loss level (in points)
input double             Signal_TakeLevel     =50.0;        // Take Profit level (in points)
input int                Signal_Expiration    =4;           // Expiration of pending orders (in bars)
input int                Signal_RSI_PeriodRSI =14;          // Relative Strength Index(14,...) M1     Period of calculation
input ENUM_APPLIED_PRICE Signal_RSI_Applied   =PRICE_CLOSE; // Relative Strength Index(14,...) M1 Prices series
input double             Signal_RSI_Weight    =1.0;         // Relative Strength Index(14,...) M1   Weight [0...1.0]
//--- inputs for money
input double             Money_FixLot_Percent =100.0;       // Percent
input double             Money_FixLot_Lots    =0.05;        // Fixed volume
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
if(!ExtExpert.Init(Symbol(),PERIOD_M1,Expert_EveryTick,Expert_MagicNumber))
  {
   //--- failed
   printf(__FUNCTION__+": error initializing expert");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//--- Creating signal
CExpertSignal *signal=new CExpertSignal;
if(signal==NULL)
  {
   //--- failed
   printf(__FUNCTION__+": error creating signal");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//---
ExtExpert.InitSignal(signal);
signal.ThresholdOpen(Signal_ThresholdOpen);
signal.ThresholdClose(Signal_ThresholdClose);
signal.PriceLevel(Signal_PriceLevel);
signal.StopLevel(Signal_StopLevel);
signal.TakeLevel(Signal_TakeLevel);
signal.Expiration(Signal_Expiration);
//--- Creating filter CSignalRSI
CSignalRSI *filter0=new CSignalRSI;
if(filter0==NULL)
  {
   //--- failed
   printf(__FUNCTION__+": error creating filter0");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
signal.AddFilter(filter0);
//--- Set filter parameters
filter0.Period(PERIOD_M1);
filter0.PeriodRSI(Signal_RSI_PeriodRSI);
filter0.Applied(Signal_RSI_Applied);
filter0.Weight(Signal_RSI_Weight);
//--- Creation of trailing object
CTrailingNone *trailing=new CTrailingNone;
if(trailing==NULL)
  {
   //--- failed
   printf(__FUNCTION__+": error creating trailing");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//--- Add trailing to expert (will be deleted automatically))
if(!ExtExpert.InitTrailing(trailing))
  {
   //--- failed
   printf(__FUNCTION__+": error initializing trailing");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
 //--- Set trailing parameters
 //--- Creation of money object
CMoneyFixedLot *money=new CMoneyFixedLot;
if(money==NULL)
  {
   //--- failed
   printf(__FUNCTION__+": error creating money");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//--- Add money to expert (will be deleted automatically))
if(!ExtExpert.InitMoney(money))
  {
   //--- failed
   printf(__FUNCTION__+": error initializing money");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//--- Set money parameters
money.Percent(Money_FixLot_Percent);
money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
if(!ExtExpert.ValidationSettings())
  {
   //--- failed
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//--- Tuning of all necessary indicators
if(!ExtExpert.InitIndicators())
  {
   //--- failed
   printf(__FUNCTION__+": error initializing indicators");
   ExtExpert.Deinit();
   return(INIT_FAILED);
  }
//--- ok
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
 {
  ExtExpert.OnTrade();
 }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+
</code>
Answer: A forma de eventos utilizada no codigo nao permite o comportamento desejado. O sinalidor do RSI vai indicar compra quando esta abaixo de, digamos de 30, com peso 10. Quando volta para cima de 30 pode estar indicando ainda compra com peso 2. Isso quer dizer que pra voce fazer o comportamento que deseja precisara alterar o codigo do gerador de evento e suas pontuacoes. Veja o codigo na area de include que fala sobre o gerador de eventos do RSI para tambem saber o que desligar da execucao padrao via chamada a funcao Pattern ou Weigth (uma analise do padrao pode ficar sempre ligada, mas nao ter contribuicao pro peso).
Outra coisa eh que uma ordem de compra pode ser aberta e fechada e nao ter a necessidade de se gerar uma ordem de venda. A geracao de uma posicao oposta para encerrar uma posicao aberta pode ser problematica se estiver trabalhando com um tipo de conta chamado hedge.


Como testar meu aplicativo feito em Xamarin no emulador do Visual Studio?

Question: Fiz um aplicativo mobile android utilizando o Xamarin e o testei normalmente, fiz algumas modificações e quando fui compilar novamente, o emulador do visual studio permaneceu com a versão antiga, me impossibilitando de testar meu aplicativo. Com isso eu desinstalei meu aplicativo do emulador, porque achei que quando eu fosse compilar, ele iria voltar, mas não voltou. Agora já não tenho nem a versão antiga.
Isso é um bug? Como eu passo meu aplicativo para o emulador do visual studio?
Answer: Sim, isso é um bug, eu estava utilizando a SDK do Android Marshmallow 6.0 e resolvi instalando uma diferente (Android Nougat 7.1).
Para trocar é só seguir os passo:

No Visual Studio vá para > Ferramentas > Android > Android SDK Manager
Instale o SDK que você deseja.
Vá para > Ferramentas > Android > Gerenciador de Emulador para Android
Crie um novo ADB, com o SDK que você acabou de adicionar.

Pronto, agora para depurar o programa, use o ADB que você criou.


Controlling the distribution of a points along a straight line

Question: I'm really struggling with what I think is a basic problem.
I'm a designer trying to code an add-on for Blender. That's not important to the problem, just thought I'd provide some context. And try to make the excuse for why I'm pretty poor at maths.
Anyway, the problem:
I have a line illustrated in figure 1 the image below:

Its length (A) can be specified by the user.
There are an amount of points along the line (B) which can also be specified by the user.
I need to be able to specify C to be between a value of 0 and 1, where 1 spaces the points out evenly (figure 1) but a value of 0 spaces the points out more akin to figure 2. And values in between start bunching the distribution of points towards the end of the line. Whatever this value is set to it can not affect the length of the line (A). That always has to remain as set.
Is there a formula to describe the behaviour?
It's easy to implement the behaviour in figure 1 and I have managed to get the distribution of the points to bunch up towards the end as the value (C) is changed. However, the length of the line (A) scales too.
Hope I've explained this appropriately.
Thanks in advance :)
Answer: There are an unlimited number of functions to accomplish this kind of transformation. A simple one can be defined as follows. Given $L$ the segment length, the function with $0 < c \le 1$ and $0 \le x\le L$
$$
f(x) = \left(\frac xL\right)^{\frac 1c}L
$$
gives a correspondence $\{x\to f(x)\}$ as desired
Comment: Thank you for taking the time to provide an answer. I'm going look into this and get back to you.
Answer: In short you're looking for a function $f : [0, L] \to [0, L]$ such that

$f$ is strictly increasing,
$f(0) = 0$,
$f(A) = A$, and
$f\left(\frac{A}{B - 1}\right) = C$.

Note that this formulation requires $0 < C < A$ and $B > 2$.)
You don't say what exactly you mean by "akin to figure 2", but I'll suppose you mean that:

The sequence of distances between successive pairs of points, that is, $$\delta_i := f\left(\frac{i}{B - 1}\right) - f\left(\frac{i - 1}{B - 1}\right), \qquad i = 0, \ldots, B - 1,$$ is (not necessarily strictly) increasing or decreasing.

A simple family of functions that satisfies these conditions (1), (2), (3), and (5) is
$$\boxed{g(x) := A^{1 - \alpha} x^\alpha , \qquad \alpha > 0} .$$
Substituting this function in equation (4) gives
$$g\left(\frac{A}{B - 1}\right) = C ,$$ that is,
$$\alpha = \log \left[ \frac{A}{(B - 1) C}\right].$$ (Notice that the quantity inside the logarithm is just the ratio $\frac{A}{B - 1}$ of the distance between evenly spaced points and the target length $C$.) For $c = \frac{1}{\alpha}$ this example coincides with Cesareo's suggestion for some values of $\alpha$.
Other families of functions satisfying (1), (2), (3), and (5) include
$$\boxed{h(x) := A \sin^{\beta} \left(\frac{\pi x}{2 A}\right) , \qquad 0 < \beta < 1} ,$$
and
$$\boxed{j(x) := A^{1 - 2 \gamma} \left(2 A x - x^2\right)^\gamma, \qquad \gamma > 0}.$$
We can find a value of $\beta$ satisfying condition (4) iff $\sin \left(\frac{\pi}{2 (B - 1)}\right) \leq \frac{C}{A}$, and we can always find a value of $\gamma$ so that $j$ satisfies (4).
Comment: Thank you for taking the time to provide an answer. And thanks for correct my typing mistake! I'm going look into this and get back to you. Additionally, that you for going into a great amount of detail in your response.
Comment: Although I've accepted the answer above based on it providing the level of simplicity I require for my simple use-case, I will eventually require more control so I will come back to your answer for a greater understanding. Really appreciate your explanation. Thanks.


A locally metrizable, Lindelöf Hausdorff space that is not metrizable

Question: I am looking for an example of locally metrizable, Lindelöf Hausdorff space that is not metrizable.
I've proved that if such space is regular, then it is metrizable. The proof relies on the ability to find Lindelöf neighborhoods inside metrizable ones, so any counterexample must be non-hereditarily Lindelöf. Unfortunately, the only few examples of such spaces I'm familiar with fail to satisfy some conditions: the particular point topology on an uncountable set is not even T1; uncountable products of compact sets are not first countable; the unit square with lexicographic order is regular.
Answer: An example of such a space is the K-topology on $\mathbb{R}$. Setting $K = \{ \frac{1}{n} : n \geq 1 \}$, the open sets are exactly the sets of the form $U \setminus A$ there $U \subseteq \mathbb{R}$ is open in the usual metric/order topology, and $A \subseteq K$.

Since the topology is finer than the usual topology, it is clearly Hausdorff.
It is not regular, since $0$ and the closed set $K$ cannot be separated by disjoint open sets. Therefore the space is not metrizable.
It  is Lindelöf since given any open cover $\{ U_i \setminus A_i : i \in I \}$ you first take a countable $I_0 \subseteq I$ so that $\bigcup_{i \in I_0} U_i = \mathbb{R}$, and note that $\mathbb{R} \setminus \bigcup_{i \in I_0} ( U_i \setminus A_I ) \subseteq K$ is countable, so we need only add countably many more sets to cover $\mathbb{R}$.  (This idea can be modified to show that the space is hereditarily Lindelöf.)
It is locally metrizable because every point has an open neighbourhood whose subspace topology with respect to the K-topology coincides with the subspace topology with respect to the usual topology. For $x \neq 0$ just take an open interval containing $x$ whose intersection with $K$ is finite.  For $x = 0$ consider $( -1  , 1 ) \setminus K$.
Comment: @MarcinŁoś: No need to feel stupid. I spent quite a while going through several weird spaces before even considering this one one. And then didn't believe it worked until I spent more time triple checking the above facts about it.
Comment: D'oh! Feels stupid, totally forgot I needed regularity also to use Urysohn's metrization theorem, so hereditarily Lindelöf is not a problem. So there is an example I'm familiar with after all. Thank you! This is a completely satisfactory answer, I'll accept it in a day or two.


take path of script as an argument python

Question: I have this python script which sits in
/some/folder/foo.py

So if I am in /some/folder and do
python foo.py

the script runs great. Now I want to take this path /some/folder as an argument, so that I can run this script when in different folder.
something like if I am in /a/different/folder and from this folder I want to execute
foo.py

How do i do this?
Thanks
Comment: I think this is really a shell question, since it would be the same for running python scripts, perl scripts, or any other program. Can you confirm?
Answer: Just include the full path of the script :
python /some/folder/foo.py

If, inside your script, you have "relative" paths, just prepend /some/folder to each of the paths.
Comment: Hi.. This would work.. except.. the file sits on a server.. and on different servers this path maybe different :(
Comment: you can always get the host name of the box you are working on by using `hostname` .
Answer: Recommendation would be to do the opposite, accept a parameter to run the script in, if its not provided to current directory.
foo.py <path_to_run_script_on>

Then all you have to do is make sure foo.py is on your path.
import sys
import os
if __name__=="__main__":
 if len(sys.argv) > 1:
   p = sys.argv[1]
 else:
  p = os.path.abspath(os.path.curdir)

 print p

Comment: Can you elaborate.. I dont think I understood it completely
Thanks
Answer: are you asking how to run this from the shell? You're looking for absolute paths:
/a/different/folder $ python /some/folder/foo.py

or relative paths:
/some/otherfolder $ python ../folder/foo.py

If you're looking to get the absolute path name of your script while running it:
import sys
import os.path

absolutePathToMe = os.path.abspath(sys.argv[0])

Answer: import os

mypath = os.path.dirname(__file__)

that will get you the path to the script that is currently being executed


O Android não reconhece o caminho do SDK

Question:
Quando acesso os diretórios que são especificados no caminho absoluto, não consigo encontrar a partir da pasta AppData. Mas o caminho absoluto funciona, quando copio e colo na busca.
Como faço para acessar o arquivo do SDK e inserir novamente seu caminho? Ou modificar seu caminho?
Answer: Resolvi o problema selecionando as opções mostradas nos prints abaixo, nessa ordem:

sincronizar arquivos locais (print 1)
sincronizar os arquivos do Gradle (print 2)


Axon complaining on com.thoughtworks.xstream.converters.ConversionException: Failed calling method

Question: I'm trying to use mysql with JPA for axon event store and I am getting this issue,It was working for me with InMemoryEventStorageEngine.
I have tried it with axon server and InMemoryEventStorageEngine, its working.
Any help is really appreciated thanks
com.thoughtworks.xstream.converters.ConversionException: Failed calling method
---- Debugging information ----
message             : Failed calling method
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Failed calling method
method              : java.util.concurrent.CopyOnWriteArrayList.writeObject()
at com.thoughtworks.xstream.core.util.SerializationMembers.callWriteObject(SerializationMembers.java:158)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.doMarshal(SerializableConverter.java:257)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:274)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:213)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:144)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:274)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:213)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:144)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:274)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:213)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:144)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1319)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1308)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:1281)
at org.axonframework.serialization.xml.XStreamSerializer.doSerialize(XStreamSerializer.java:86)
at org.axonframework.serialization.AbstractXStreamSerializer.serialize(AbstractXStreamSerializer.java:98)
at org.axonframework.modelling.saga.repository.jpa.AbstractSagaEntry.<init>(AbstractSagaEntry.java:58)
at org.axonframework.modelling.saga.repository.jpa.SagaEntry.<init>(SagaEntry.java:41)
at org.axonframework.modelling.saga.repository.jpa.JpaSagaStore.createSagaEntry(JpaSagaStore.java:330)
at org.axonframework.modelling.saga.repository.jpa.JpaSagaStore.insertSaga(JpaSagaStore.java:298)
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.storeSaga(AnnotatedSagaRepository.java:217)
at org.axonframework.modelling.saga.repository.AnnotatedSagaRepository.lambda$doCreateInstance$3(AnnotatedSagaRepository.java:139)
at org.axonframework.messaging.unitofwork.MessageProcessingContext.notifyHandlers(MessageProcessingContext.java:71)
at org.axonframework.messaging.unitofwork.BatchingUnitOfWork.lambda$notifyHandlers$2(BatchingUnitOfWork.java:155)
at java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:899)
at org.axonframework.messaging.unitofwork.BatchingUnitOfWork.notifyHandlers(BatchingUnitOfWork.java:155)
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.changePhase(AbstractUnitOfWork.java:222)
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commitAsRoot(AbstractUnitOfWork.java:83)
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commit(AbstractUnitOfWork.java:71)
at org.axonframework.messaging.unitofwork.BatchingUnitOfWork.executeWithResult(BatchingUnitOfWork.java:111)
at org.axonframework.eventhandling.AbstractEventProcessor.processInUnitOfWork(AbstractEventProcessor.java:136)
at org.axonframework.eventhandling.TrackingEventProcessor.processBatch(TrackingEventProcessor.java:259)
at org.axonframework.eventhandling.TrackingEventProcessor.processingLoop(TrackingEventProcessor.java:181)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:661)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:771)
at org.axonframework.eventhandling.TrackingEventProcessor$CountingRunnable.run(TrackingEventProcessor.java:588)
at java.lang.Thread.run(Thread.java:748)

Comment: The fact the `InMemoryEventStorageEngine` works, is because that will not de-/serialize anything. Thus, the `XStreamSerializer` Axon Framework defaults to wouldn't be used in that scenario.
To get to the point though, place share the exact object which XStream is trying to serialize. It's likely something to do with how you've drafted up the given Event which doesn't work.
Answer: As @Steven mentioned serialization works only when you try to store the events in DB,and you can easily configure your event serialization in your configuration application properties,
I was able to solve it using this configurations
axon.serializer.general = jackson
axon.serializer.events = jackson
axon.serializer.messages =Jackson

Answer: @dawit Do you get the solution or work around to solve it


Python writes 0 to the file

Question: import os

fileHandle = open('booksNames.txt', 'r+')

def getData():
    data = os.system('dir /b /a /s *.pdf *.epub *.mobi')
    fileHandle.writelines(str(data))

fileHandle.close()

I'm trying to write the data returned by the os.system function to a file. But the only thing that gets written in file is 0. Here are some other variations that I tried as well.
import os

fileHandle = open('booksNames.txt', 'r+')

getData = lambda:os.system('dir /b /a /s *.pdf *.epub *.mobi')
data = getData()

fileHandle.writelines(str(data))
fileHandle.close()

On the output window, it gives perfect output but while writing to a text fileit writes zero. I've also tried using return but no use. Please Help.
Comment: `os.system` does not return the output printed by the command line executed. It returns the process's exit status, which is 0.
Comment: @user2357112, that should be an answer when you add the correct call
Comment: The first variation contains two errors at least: 1) 'r+' is incorrect; 'r' for read(only) and 'w' for write (which is what you want).  2) the function GetData is never called.
Comment: @SurestTexas `'r+'` is read/write starting at the beginning of the file and so is fine
Comment: @SurestTexas: `r+` is opening for read/write.
Comment: @SurestTexas indeed but his file is open for reading **and** writing
Comment: interesting.. did not know you could do that :)
Comment: I still think "Explicit is better than implicit".  I don't get why the OP wants to open the same file in read and write modes. It appears they want the output of the command written to a file... why not just make the command output its results to the text file directly?
Comment: what OS is this? Windows, or a Unix..?
Answer: Use the subprocess module.  There are a number of methods, but the simplest is:
>>> import subprocess
>>> with open('out.txt','w') as f:
...     subprocess.call(['dir','/b','/a','/s','*.pdf','*.epub','*.mobi'],stdout=f,stderr=f,shell=True)
...
0

Zero is the exit code, but the content will be in out.txt.
Comment: The file system encoding is UTF-16LE, but this has cmd.exe encode the `dir` output using either the console's current output codepage (defaults to OEM) or ANSI if there's no console attached. That's ok if all of the filenames can be encoded in the OEM or ANSI codepages. But otherwise you'll have to remove `shell=True`; execute `'cmd.exe /u /c "{}"'.format(cmdline)`; and decode the output as UTF-16LE.
Comment: Also, in general you shouldn't use a list with `shell=True`. `subprocess.list2cmdline` isn't written for the cmd shell; it's written for MSVC `argv` parsing.
Answer: For windows (I assume you are using Windows since you are using the 'dir' command, not the Unix/Linux 'ls'):
simply let the command do the work.
os.system('dir /b /a /s *.pdf *.epub *.mobi >> booksNames.txt')

Using '>>' will append to any existing file.  just use '>' to write a new file.
I liked the other solution using subprocess, but since this is OS-specific anyway, I think this is simpler.
Comment: `with` is a better way to manage closing the file, but it doesn't do anything about the `0` thing.

Python writes 0 to the file


Can you use Cox Regression to model non-linear relationships?

Question: The question says it all - I'm just wondering whether Cox regression models are used to model non-linear relationships.
Comment: Does this answer your question? [Why is polynomial regression considered a special case of multiple linear regression?](https://stats.stackexchange.com/questions/92065/why-is-polynomial-regression-considered-a-special-case-of-multiple-linear-regres) Although that question is about ordinary linear regression, the principle is the same for all linear regression models like Cox models: the linearity is in the parameters to be estimated, not in the associated predictors. Polynomial and spline methods allow nonlinear terms for predictors while the model is still linear in their coefficients.
Answer: It depends on what you mean by non-linear. The Cox model can handle non-linear covariates through the use of spline terms on the covariate. See this, for example:
https://cran.r-project.org/web/packages/survival/vignettes/splines.pdf


Connect to iBeacon

Question: I can scan for iBeacons with:
func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) {

  }
}

let suppose I get the following beacons after scanning
Beacon 1: major:1 minor:5 uuid:xxx
Beacon 2: major:1 minor:6 uuid:xxx
Beacon 3: major:1 minor:7 uuid:xxx

After the scan I want to connect to beacon 2 and change its characteristics.
I know I can use CoreBluetooth to scan and connect to a Bluetooth device and change its characteristics, but the problem is how can I identify which device is beacon 2 via Core Bluetooth?
Answer: You cannot obtain any information that directly relates a CLBeacon to a  CBPeripheral.
Typically the beacon's GATT service will expose a "device name" characteristic that you can display to the user to allow them to select the device to be configured from a list.
As David pointed in the comments, any such GATT service will be vendor specific, or it may not even exist, with the beacon being configured through some other method, such as USB. Even where a GATT service is provided it may be disabled through configuration or only active for a limited period after initial power-on.
There is no generic "configure an iBeacon" service defined.
Comment: To add to Paul's answer, not all beacons have connectable GATT services.  Some manufacturers do provide this for configuration, but you cannot use CoreLocation APIs.  You must use CoreBluetooth APIs.  And the specifics of how you do so are all vendor-specific.  Ask your beacon manufacturer if they have docs for a public config GATT service. You cannot correlate beacon detections to CoreBluetooth devices.  Apple unfortunately blocks this.
Comment: Another approach that will work is to advertise custom payload agter certain interval with uuid , major,minor and do both CLBeacon and CBPeripheral scanning, when user clicks on specific ibeacon connect it via CBPeripheral
Comment: Connecting to a beacon is not a good option if you have a list of like 200 or 100 beacons.I think it is good to broadcast two types of beacons 1. ibeacon and 2.custom beacon(contains uuid,major,minor and broadcasted at certain interval and will be scan-able with Corebluetooth) and when i want to connect to specific i beacon connect via equivalent  CBPeripheral.
Comment: what i get is there is no way to relate CLBeacon with CBPeripheral, in order to relate both i need to connect all beacons and check one by one and then identify the right beacon because the beacon i am using also exposes its major/minor/uuid via gatt. but this approach is useless if i have more beacons like 20+
Comment: As David said, it depends on your beacon; some may expose a useful name via their GATT service.  There is no standard way of configuring beacons
Comment: yes; exactly; the GATT service is something you have to define (if you are making your own beacon device) or something that the manufacturer will have defined.
Comment: @Paulw11 i know uuid, major and minor is exposed via gatt service, i have verified it with android and i know the relevant characteristics to read.
Comment: Then you should be able to write some simple code that can discover the service, connect to the beacon, read the major/minor/uuid and then disconnect.  Execution of that won't take long; no more than a second or two
Comment: And yes i am working with my own beacon so i can do firmware level changes too.

Connect to iBeacon


Can PlatformView on flutter help build AdMob BannerAd widget for flutter?

Question: The firebase_admob plugin has support for banner ad which can be placed only on a fixed set of positions (top,bottom) because its just putting native view in top of the flutters activity/ViewController. Is it possible no to export BannerAd as a widget using PlatformView?
Or is it somehow possible right now to add banner ad inside a scrollable widget of flutter.
Answer: You can try thís https://pub.dartlang.org/packages/flutter_native_admob. It uses exact PlatformView as you expect. But the limitation is not supporting iOS yet.

Warning: The plugin is based on Flutter PlatformView (AndroidView) to
  create a custom widget from Native View. Therefore, only Android is
  supported at the moment. For iOS, wait for Flutter team to implement
  iOSView equivalent.


In Rasterio - how to tile an array representing a geo-referenced image when the Affine object is separate?

Question: I am attempting to tile a large image (.img format, but could be geotiff), however I have already cropped the image using rasterio mask which returns a masked array and a separate Affine object.
from rasterio import mask
import fiona

image = rasterio.open(image_path)
with fiona.open(shapefile_path, 'r') as shapefile:
    cropping_polygon = [polygon['geometry'] for polygon in shapefile]

smaller_image, smaller_image_affine = mask.mask(image, cropping_polygon, crop=True)

Now I want to split the smaller_image into tiles of a fixed size. I have looked at rasterio windowed reading and writing but this seems to rely on the image having the image.affine attribute in order not to lose the geo-referencing.
Is it possible to tile the masked array, and produce a new affine for each tile?
Answer: I think you are looking for rasterio.windows.transform.
tile_window = rasterio.windows.Window(0, 0, 256, 256)
tile_affine = rasterio.windows.transform(tile_window, smaller_image_affine)
tile_image = smaller_image[(slice(None),) + tile_window.toslices()]

Then with tile_image and tile_affine you have all the pieces you need to write this to a new file.
Comment: Perfect answer thank you - not sure how I missed this!


How to parse a Datetime with format "MM/dd/YY" in flutter

Question: So far I try new DateFormat("MM/dd/yy").parse('04/03/20') but it produce 04/03/0020 date.
Comment: How will you be able to tell if that date refers to year 2020 or 1920?
Comment: https://github.com/dart-lang/intl/issues/123
Answer: var currentDate=DateTime.now().day;
 var currentYear=DateTime.now().year;
 var currentMonth=DateTime.now().month;

 String month=currentMonth.toString();
 if(currentMonth<=9){
   month="0$month";
 }

 String yearShort=currentYear.toString().substring(currentYear.toString().length-2);
 String values="$currentDate/$month/$yearShort";

Answer: You have to formate this date using formate method of datetime class. However, you need to convert string to datetime using parse method because datetime formate take datatime as an argument.
Following line help you to achieve desire output:
 print(DateFormat("MM/dd/yy")
        .format(DateFormat("MM/dd/yy").parse('04/03/20')));

UPDATE:
This following code will give result as you expected but it is hard to find out it is 1920 or 2020?
 DateTime _dateTime = DateFormat("mm/dd/yy").parse('04/03/20');
    _dateTime = DateTime(2000 + _dateTime.year, _dateTime.month, _dateTime.day);
    print(_dateTime);

Comment: What I really need is the DateTime object. Note that if you do  print(DateFormat("MM/dd/yyyy").format(DateFormat("MM/dd/yy").parse('04/03/20'))) the result is the same wrong value '04/03/0020' but I need '04/03/2020'
Comment: How will you be able to tell if that date refers to year 2020 or 1920? as @jamescasia mention. do you want 20 everytime ?


Find k when L2 passes through the P1 with direction vector

Question: Q: Let L1 be the line passing through the points
 Q1=(−3, 5, −4) and Q2=(−9, −1, 2).
 Find a value of k so the line L2 passing through the point P1 = P1(−1, 11, k) with direction vector
→d=[1, −3, −3]T intersects with L1.
k = ?
Can someone please show me the answer and how they got it. This is what I have done so far:
v1 = Q2 - Q1 = (-6, -6, 6)
L1:
x = -3 -6t
y = 5  - 6t
z = -4 + 6t
L2
passing through the point P1 = P1(−1, 11, k) with direction
vector →d=[1, −3, −3]:
x = -1 - 1
y = 11 - 3
z = k -3
L₁ will intersect L₂ IF the simultaneous equation admit a solution
-3 -6t = 1 - 1
11 - 3 = 5  - 6t
-4 + 6t = k -3
**On a sidenote does anyone else have difficulty with really long calculations? I've understood the concept for similiar questions but when it comes to the computation my brain just completely shuts down and I make lots of silly mistakes :( **
Answer: You're on the right track. Your first line has equations:
$$
\begin{bmatrix}
x\\y\\z
\end{bmatrix}
=
\begin{bmatrix}
-3\\5\\-4
\end{bmatrix}
+ t \begin{bmatrix}
-6\\-6\\6
\end{bmatrix}
$$
You didn't have any parameter on your second line so you are missing some variables in your system. The second line has equation:
$$
\begin{bmatrix}
x\\y\\z
\end{bmatrix}
=
\begin{bmatrix}
-1\\11\\k
\end{bmatrix}
+ s \begin{bmatrix}
1\\-3\\-3
\end{bmatrix}
$$
If you now simultaneously solve these you should be able to find $k$.
As for tips for long calculations, I think a lot of it boils down to practice. As you do more problems you will build intuition for the big steps you need to take to solve different types of problems, and also for things which might have gone wrong if you get stuck.
For instance, the system you obtained has no solution. However, if you think about the lines in real life it seems like there should be a solution. So you can then go back and try to look at why your system didn't have a solution.
Sometimes it also helps to slow down and really write out what you are doing at each step. I also make a lot of mistakes even when I have an idea how to solve the problem, and sometimes it just takes me sitting down and being very deliberate about each step of the solution to eliminate all my silly mistakes.
Comment: found the answer thanks
Answer: I find it helpful to think a bit about about the geometry of the situation before plunging into writing equations. If two lines intersect, then they are coplanar. In particular, that $Q_1$, $Q_2$ and $P$ $L_2$ lies in this plane, so its direction vector $\mathbf d$ must be parallel to the plane, which also means that it is orthogonal to the plane's normal. These conditions translate into the equation $$[(Q_1-P)\times(Q_2-P)]\cdot d=0.$$ Fill in the values from your problem and solve for $k$.


Exponential decay function

Question: I have a model where I assumed a variable X would have an exponential decay over time t. I modeled it in R as
$$N = N_1e^{kt},$$
where $k < 0$ and $t$ is 1:95.
However, looking are some real data that I have captured, it seems that the decay is slightly slower to begin with but is much faster towards the end. The greatest gap in my projected data and the actual data is in the middle.
Beginner question, but I was wondering is that type of decay was a known function, or is there some way for me to model it with the exponential decay function.
I have a plot of the two functions, but am not allowed to upload it here. The plot shows a symmetry between the two sets of data, as if the actual data plot is a mirror image of the model data.
I generate the model data using this
gf <- 1.35 * exp(-0.00946 * 1:95)

and the actual data gf2 is
    c(1.35, 1.33776990615813, 1.32552158334356, 1.31325480792751,
1.30096935107516, 1.28866497856582, 1.27634145060489, 1.26399852162705,
1.25163594009013, 1.23925344825924, 1.22685078198044, 1.21442767044339,
1.20198383593233, 1.18951899356456, 1.17703285101575, 1.1645251082312,
1.15199545712208, 1.13944358124587, 1.12686915546963, 1.11427184561532,
1.10165130808571, 1.08900718946957, 1.07633912612483, 1.06364674373805,
1.05092965685848, 1.03818746840501, 1.02541976914382, 1.01262613713477,
0.999806137143936, 0.986959320019858, 0.974085222030623, 0.961183364158636,
0.948253251349736, 0.935294371712896, 0.922306195666412, 0.909288175026071,
0.896239742030314, 0.883160308296893, 0.870049263704956, 0.856905975195814,
0.843729785484912, 0.830520011676707, 0.817275943773186, 0.803996843065683,
0.790681940398468, 0.777330434291129, 0.763941488905233, 0.75051423183888,
0.737047751730707, 0.723541095652442, 0.70999326626635, 0.696403218720661,
0.682769857252295, 0.669092031461845, 0.655368532220595, 0.64159808716336,
0.627779355713794, 0.613910923580398, 0.599991296651462, 0.586018894205227,
0.571992041337234, 0.557908960489589, 0.543767761945991, 0.529566433130946,
0.51530282652052, 0.500974645933667, 0.486579430925755, 0.472114538946752,
0.457577124852233, 0.44296411726136, 0.428272191135991, 0.413497735800733,
0.398636817423197, 0.383685134710617, 0.368637966230041, 0.353490107290977,
0.338235793692888, 0.322868608762547, 0.30738136887844, 0.291765980931759,
0.276013262639391, 0.260112712872577, 0.24405221348003, 0.227817635241112,
0.211392306411718, 0.19475627881785, 0.177885285875707, 0.160749213513732,
0.143309764509418, 0.125516708879546, 0.10730146998924, 0.0885651903719612,
0.0691537518211836, 0.048795218179725, 0.0268838502712772)

Comment: Maybe you can give more specifics to the problem, as what is the purpose of the model?
If you're trying to predict future values, if you're trying to estimate k, or if you're trying to validate/reject the model, there would be different answers depending on what you want to do.
Comment: I have a Poisson distribution with a lambda of 1.35. The distribution is modeled over 95 minutes. I want to adjust the lambda as a function of t, i.e. calculate lambda for t = 1,2,3..95. I had assumed that this would be an exponential decay, but the actual data has it decaying faster towards the end.
Comment: If you post the data you'll get a better response.  Try `dput()`.
Comment: I've added the data to the question.
Comment: Post the results of `dput(gf2)`.   It makes things a lot easier.
Comment: @bill_080 Done. Sorry new to R.
Comment: Not a problem.   That's how a lot of people discover `dput()`.
Comment: You might try fitting a Weibull function...
Answer: First, in its current form, this isn't an exponential.   Here is the code with some plots:
gf2 <- c(1.35, 1.33776990615813, 1.32552158334356, 1.31325480792751,
1.30096935107516, 1.28866497856582, 1.27634145060489, 1.26399852162705,
1.25163594009013, 1.23925344825924, 1.22685078198044, 1.21442767044339,
1.20198383593233, 1.18951899356456, 1.17703285101575, 1.1645251082312,
1.15199545712208, 1.13944358124587, 1.12686915546963, 1.11427184561532,
1.10165130808571, 1.08900718946957, 1.07633912612483, 1.06364674373805,
1.05092965685848, 1.03818746840501, 1.02541976914382, 1.01262613713477,
0.999806137143936, 0.986959320019858, 0.974085222030623, 0.961183364158636,
0.948253251349736, 0.935294371712896, 0.922306195666412, 0.909288175026071,
0.896239742030314, 0.883160308296893, 0.870049263704956, 0.856905975195814,
0.843729785484912, 0.830520011676707, 0.817275943773186, 0.803996843065683,
0.790681940398468, 0.777330434291129, 0.763941488905233, 0.75051423183888,
0.737047751730707, 0.723541095652442, 0.70999326626635, 0.696403218720661,
0.682769857252295, 0.669092031461845, 0.655368532220595, 0.64159808716336,
0.627779355713794, 0.613910923580398, 0.599991296651462, 0.586018894205227,
0.571992041337234, 0.557908960489589, 0.543767761945991, 0.529566433130946,
0.51530282652052, 0.500974645933667, 0.486579430925755, 0.472114538946752,
0.457577124852233, 0.44296411726136, 0.428272191135991, 0.413497735800733,
0.398636817423197, 0.383685134710617, 0.368637966230041, 0.353490107290977,
0.338235793692888, 0.322868608762547, 0.30738136887844, 0.291765980931759,
0.276013262639391, 0.260112712872577, 0.24405221348003, 0.227817635241112,
0.211392306411718, 0.19475627881785, 0.177885285875707, 0.160749213513732,
0.143309764509418, 0.125516708879546, 0.10730146998924, 0.0885651903719612,
0.0691537518211836, 0.048795218179725, 0.0268838502712772)

plot(gf2) #Plot gf2
plot(diff(gf2)) #Plot the change in gf2

Notice that the last change in gf2 (see the above plot for diff(gf2)) on the far right hand side is the biggest change.   If you fit gf2 directly (probably with a ratio of polynomials), the biggest residual will probably be in the last data point.   So, you might try a fit for the difference in gf2 and then sum it up.
Looking at the second plot for diff(gf2), it looks like a logarithmic plot that was simply flipped.   Here's some code and a plot to show that:
gf2_rev <- rev(gf2) #Reverse gf2
plot(diff(gf2_rev)) #Plot it

If you fit that third graph, you'll get a simple equation.   From there, you'll have to flip it back to get the second plot, and then accumulate the sum to get the first plot.
The alternative is to fit a ratio of polynomials that will have a hard time with that far right data point.
Edit 1 (01/14/2012) ================================================
After some playing around with the data, I came up with the following.
First, as described above, that far right data point makes this a little harder, so I decided to fit the difference in gf2 (diff(gf2)) and then sum the results up to get gf2.  Here are the results (the fit is in red):
ind <- 1:94
#Here's the fit equation
diff_gf2_trial <- -0.1283/log(3.666e4 + (2.01*(ind^2)) - (575.4*ind))

plot(diff(gf2), main="Fit the difference so the far right data point works")
lines(diff_gf2_trial, col="red") #Overlay the fit equation in red

gf2_trial <- cumsum(c(gf2[1], diff_gf2_trial)) #Build the cumulative sum
plot(gf2, main="Sum up the fit to get the estimated gf2")
lines(gf2_trial, col="red") #Overlay the cumulative sum in red

Hope that helps.
Edit 2 (01/14/2012) =========================================
The general form of the equation came from plotting and rough fitting the data in various ways.   My target was a clean fit with a model that was as simple as possible.   I settled on a negative inverted exponential.  The curve looked reasonably quadratic or cubic.   After some quick fits, it turned out that a quadratic was good enough. Here's the code for that plot (I realize that the above description sounds like a bunch of weasel-words, however it comes from experience and a lot of playing around with the data).
plot(exp(-1/diff(gf2)), main="Plot of exp(ScaleValue/diff(gf2))")
lines(exp(-0.99/diff(gf2)), col="green")
lines(exp(-0.98/diff(gf2)), col="orange")
lines(exp(-0.97/diff(gf2)), col="purple")

At this point, all I have to do is figure out the ScaleValue for exp(ScaleValue/diff(gf2)) and then perform a linear fit for the quadratic terms that fit the above plot.  Here's the code:
library(DEoptim) #An optimizer

#Build a function that allows the Scale Value (scaval) to vary and
#return 1 - Adjusted R-Squared value (so it can be minimized).
#In other words, for each "scaval" value that is tried, fit all of
#the polynomial terms.

minfun <- function(scaval) {
  1 - summary(lm(exp(as.numeric(scaval)/diff(gf2)) ~ poly(ind, degree=2, raw=TRUE)))$adj.r.squared
}

ind <- 1:length(diff(gf2)) #Make an index for the difference in gf2 to be used in minfun
junk <- DEoptim(minfun, lower=-1, upper=-0.0001) #Find the Scale
scaval <- as.numeric(junk$optim$bestmem) #Get the answer returned from the optimizer

#Build the resulting model
res <- lm(exp(scaval/diff(gf2)) ~ poly(ind, degree=2, raw=TRUE))
summary(res)

#Here's the fit equation
diff_gf2_new <- scaval/log(res$coefficients[1] + (res$coefficients[2]*ind) + (res$coefficients[3]*(ind^2)))
plot(diff(gf2), main="Fit the difference so the far right data point works") #Plot the difference in gf2
lines(diff_gf2_new, col="blue") #Overlay the fit equation in blue

Notice that the coefficients for diff_gf2_new may be a little different than diff_gf2_trial.   That's because I originally used weights to make sure that the far right data point was represented cleanly.  It turns out, those weights aren't really needed.   Here's the final fit:
summary(res)

Call:
lm(formula = exp(scaval/diff(gf2)) ~ poly(ind, degree = 2, raw = TRUE))

Residuals:
     Min       1Q   Median       3Q      Max
-117.090  -64.603   -6.481   57.591  292.487

Coefficients:
                                 Estimate Std. Error t value Pr(>|t|)
(Intercept)                         2.671e+05  2.443e+01   10935   <2e-16 ***
poly(ind, degree = 2, raw = TRUE)1 -4.865e+03  1.187e+00   -4099   <2e-16 ***
poly(ind, degree = 2, raw = TRUE)2  2.161e+01  1.211e-02    1786   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 77.27 on 91 degrees of freedom
Multiple R-squared:     1,  Adjusted R-squared:     1
F-statistic: 4.742e+07 on 2 and 91 DF,  p-value: < 2.2e-16

Comment: Bill,
This is really good. Could I ask you to explain a little how

    `-0.1283/log(3.666e4 + (2.01*(ind^2)) - (575.4*ind))`

works and where you derived the constants.

Many thanks.
Comment: @JPT - I added my response above as Edit 2.
Comment: @JPT - Yesterday, I was in a hurry, so today I was just cleaning up my answer.  All I can say about fitting data is that unless you have a reason for a specific form of the equation, you'll just have to fool around with the fit until it's acceptable.   Good luck.
Comment: This is very educational, and I am working _slowly_ through each step. Still not sure though, how my initial lambda, that is decaying over time fits in here. The lambda is different for each event that I model. It was 1.35 for this sample set, but can be in a range from 1.1 to 4.0. I'll keep studying the code to find it.
Many thanks for all you help, it's much appreciated.

Exponential decay function


Eclipse - Installed PyDev and nothing changed

Question: This isn't my first time using Eclipse or installing PyDev but this is the first time it both succeeded and failed.
It succeeded because it installed, it shows up as being installed and installation went on fine without a problem.
It failed because nothing has shown up, there is no Python perspective, no PyDev views in the view list, no new projects under PyDev, no PyDev preferences. It is as if it is not actually installed at all.
The only thing I did differently is extract the latest eclipse to a folder called ~/eclipse and create a short cut to run it there (the latest Eclipse), usually I use apt-get to install eclipse, realise it's an old version (C++11 stuff missing) then upgrade and do this. Somehow PyDev is usually carried forward.
I'm not sure how it can list it as being installed but have this error, I'd appreciate any help you guys can offer.
Answer: I bet it's the problem of 3.x version of PyDev. It demands java 7.
2 solutions are possible:

Install java 7. re-run the Eclipse, Pydev should function well now. OR
Install last 2.x version of PyDev.
To do it
1) Remove PyDev : In Eclipse About window click Installation Details
button below. You will see controls for removing plug-ins.
2) Install 2.x version of PyDev:

Eclipse Help->Install New Software.
REMOVE CHECKBOX "Show only the latest version" located at the bottom of the dialog.
Choose Pydev update site from the list and in the appeared list of PyDev versions choose latest in 2.x branch.
Comment: It worked, but before I tick I'd like to ask about the java 7 option, I installed openjdk-7.* (everything with a 7) and still no luck, but I didn't try reinstalling PyDev after, should I reinstall to test this, also checkboxes not radiobuttons governed what versions I could install, can I install multiple versions, if so how does switching work? (while I love eclipse, evidently there are many menus I have yet to explore :P)
Comment: Ok. Multiple versions of plug-in - neither tried nor imagine how to switch. Sorry. Java7 - you should tell Eclipse which java to use OR remove other java packages from the system OR define java7 as default java. To check the currently used java version in Eclipse see About Eclipse -> Installation Details -> Configuration tab. Line starting with: java.runtime.version=...
Answer: The problem is really that sometimes even installing java 7, Eclipse does not get it.
In http://pydev.org/download.html, there's a section called: PyDev does not appear after install!
Try to follow it to see if it fixes your problem (i.e.: making Eclipse find java 7).
Another option would be using PyDev standalone (i.e.: LiClipse). Although it's commercial, it should come with all the requisites builtin (so, no hassles to install) and is updated whenever PyDev itself is updated.


If y(x) is a solution to a differential equation, why is xy(x) also a solution?

Question: I'm taking an intro to ODE's course and we've been taught that in situations when we have two linearly dependent solutions, for example $y_1=e^x$ and $y_2=e^x$, we can multiply this solution by x to get a linearly independent solution. So in this case we would get $y(x)=c_1 e^x +c_2 xe^x$. Are there constraints for when this is true? Can we always multiple a solution by the independent variable to get another linearly independent solution? Why wouldn't the above solution instead be $y(x)=c_1 e^x +c_2 xe^x +c_3 x^2e^x$?
Comment: See for instance the recent question https://math.stackexchange.com/questions/4410687 and follow the links (and the links of links) in the right sidebar "Links" to older discussions on this topic.
Answer: No, this does not always work; it's a special thing in constant coefficient equations with repeated roots. The fact that multiplying by $x$ yields a function linearly independent from the one you started with is not special, but the fact that multiplying by $x$ yields another solution at all is special.
One way to see where it comes from is to solve the equation by operator factorization instead of guess-and-check. So if you have a double root of $\lambda$, you can write that as $(D-\lambda)(D-\lambda)y=0$. This suggests substituting $z=y'-\lambda y$, which gives $z'-\lambda z=0$. You can solve that by integrating factors (as you studied earlier in your course). Doing that you get $z=z_0 e^{\lambda x}$.
So now $y'-\lambda y=z=z_0 e^{\lambda x}$, so solving that by integrating factors looks like
$$\int_0^x \frac{d}{dx} \left ( e^{-\lambda t} y(t) \right ) dt = \int_0^x z_0 dt \\
e^{-\lambda x} y - y_0 = x z_0 \\
y = e^{\lambda x}(y_0+xz_0).
$$
You see that this factor of $x$ comes out because the integrating factor exactly cancels out the exponential.
You can do the same thing when you're solving for particular solutions when the right side (or a term in it) is of the form $x^k e^{\lambda x}$.
There is a deeper explanation using linear algebra. Here, these formulas fall out of some Taylor series that appear when you take the matrix exponential $e^{Jx}$, where $J$ is a special kind of matrix called a Jordan block. But if you haven't studied linear algebra already then I would not worry about this for the moment.
Answer: This occurs when you try to solve a linear ODE with constant coefficients, namely $y' = A y$ (where $A$ is a matrix). In the specific case that you have $y_1 = e^x$ and $y_2=e^x$ as the two linearly dependent "defective" solutions, then $y(x) = c_1 e^x+c_2xe^x$ is the form of the general solution. There is no $x^2 e^x$ term. (Note: "defective" is an important requirement here. It means that the corresponding eigenvalue of the matrix $A$ has no two linearly independent eigenvectors.)
If you have $y_1 = e^x$, $y_2=e^x$ and $y_3 = e^x$ as three linearly dependent solutions and if the corresponding eigenvalue of $A$ has defectiveness $2$, then you have $y(x) = c_1 e^x+c_2xe^x + c_3x^2e^x$ as the general form of the solution.
The deeper reasoning you are looking for is related to concepts from linear algebra: namely the Jordan form of a matrix, Jordan chains and defective eigenvalues. Assuming that you understand these concepts, you can find how to construct the general solution of $y' = A y$ explained here.
Comment: Your notation seems a bit mixed up. If $y(x)=c_1 e^x + \dots$ is a scalar-valued function, then it's not the same as the $y$ in matrix equation $y'=Ay$.
Comment: @HansLundmark The constants $c_n$ were meant to be vectors. But I can see how I should have made that more clear.
Comment: Well, it still seems weird to write $y_1=e^x$ then...


Artificially generate key events in other programs

Question: Can a C# program that has focus artificially generate a key event that will be handled by another open application?
For those who are curious, this is why I'm asking:
I'm currently working on a demo/mockup for a design idea for a gesture based media player, using the Kinect as a primary input device. This is something I decided to do on as a favor, and it neither needs nor deserves a ton of my time as far as programming goes.
So to speed things along, I'm using the FAAST tool which you can use to easily bind key events to certain gestures. So, you turn on this program, tell it what key maps to what gesture, then when you make the gesture the key is registered as pressed by the current application.
What I would like to create is a go-between that will display a simple GUI that I'll display to the audience. At a certain point, the user will make the "select" gesture, and I want music to start playing in an open media player. So, I would check their place in the menu hierarchy, see that they've selected "music" based on some key I choose to arbitrarily mean select, then generate a key event with the MediaPlayPause key.
Comment: You want to interact with the menu in the other application, or the menu will be in your application? It's fairly trivial to send an event to another window, but determining the state of another application is much harder.
Answer: It requires a little p/invoke work to do from C# but it's not complicated. You'll use the FindWindow API to get an hWnd for the target program, then the PostMessage API to send key events:
<code>[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

private const UInt32 WM_KEYDOWN = 0x0100;
private const UInt32 WM_KEYUP = 0x0101;

public static void SendSelect(IntPtr HWnd)
{
    PostMessage(HWnd, WM_KEYDOWN, KeyInterop.VirtualKeyFromKey(System.Windows.Input.Key.Enter), 0);
}
</code>


Cannot get AJAX callback values to save

Question: I am using Drupal 7, and I have a content type called Case Record that has the following fields:

Title  (title, Node module element)
Case Number (field_cr_case_number, Text)
Case Title (field_cr_case_title, Text)

When the user creates a new node of this type and enters in a Case Number, an AJAX call is supposed to fetch the Case Title and populate it on the Case Title textbox. Here is my module code:
<?php
/**
 * @file
 * Module for Case Records.
 *
 * @category Examples
 *
 * @package Example Modules
 */

/**
 * Implements hook_form_alter().
 */
function case_records_database_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'case_record_node_form':

      $form['field_cr_case_number'] = array(
        '#type' => 'textfield',
        '#title' => 'Case Number',
        '#prefix' => '
',
        '#suffix' => '
',
        '#ajax' => array(
          'callback' => 'case_records_database_ajax_callback',
          'event' => 'change',
          'method' => 'replace',
          'wrapper' => 'div-case-name-element-wrapper',
        ),
      );

      $cs_short_title = "";
      if (isset($form_state['values']['field_cr_case_number'])) {

        // Code omitted. Use db_select to query the database and
        // get the real case title, but for now we'll just call it
        // "Some Case Title".
        $cs_short_title = "Some Case Title";
      }

      $form['field_cr_case_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Case Title'),
        '#value' => $cs_short_title,
        '#prefix' => '
',
        '#suffix' => '
',
      );

      break;
  }
}

/**
 * AJAX callback.
 */
function case_records_database_ajax_callback($form, &$form_state) {
  return $form['field_cr_case_title'];
}

The AJAX call does indeed populate the Case Title text field with the dummy "Some Case Title" text. However, when I save the new node neither the Case Number field nor the Case Title field are saved with any values. They are both blank. What is wrong with my code?
Answer: That code is overriding the fields structure. That fields have a specific structure and that code is changing it completely, so in submit the values are not recognized.
I recommend you use devel module and use dpm function to inspect the structure of that fields:
  dpm($form['field_cr_case_number']);
  dpm($form['field_cr_case_title']);

To make your form changes you must only add the #ajax property to your field:
$form['field_cr_case_number'][LANGUAGE_NONE][0]['value']['#ajax'] = array(
  'callback' => 'case_records_database_ajax_callback',
  'event' => 'change',
  'method' => 'replace',
  'wrapper' => 'div-case-name-element-wrapper',
);

And to add the wrapper and #value to your second field do something like this:
$form['field_cr_case_title'][LANGUAGE_NONE][0]['value']['#prefix'] = '
';
$form['field_cr_case_title'][LANGUAGE_NONE][0]['value']['#suffix'] = '
';
$form['field_cr_case_title'][LANGUAGE_NONE][0]['value']['#value'] = $cs_short_title;

In this question is also explained how to make the ajax callback.
Comment: The second line of the second field says "#prefix" when it should say "#suffix" but other than that, thank you very much that worked perfectly you're a genius.
Comment: thx, I replace it in case other people want reference

Cannot get AJAX callback values to save