How can I make my upside-downed stacked graph right using d3.js?

Question: Chapter 11 of "Interactive Data Visualization for the Web" shows how to create stacked bar charts with the D3.js library. The example produces an upside down chart with the bars attached to the top of the x-axis.
Upside-down

This is the code that makes stacked bar upside down.
and when I change several codes like following:
1) Change the yScale .range from:
.range([0, h]);

to
.range([h, 0]);

2) Change the rect "y" .attr from:
.attr("y", function(d) { return yScale(d.y0); })

to
.attr("y", function(d) { return yScale(d.y0) + yScale(d.y) - h; })

3) Change the rect "height" .attr from:
.attr("height", function(d) { return yScale(d.y); })

to
.attr("height", function(d) { return h - yScale(d.y); })

With those changes applied, the stacks attach to the bottom and still maintain their relative sizes.
right graph
The problem is, I don't get the meaning of the second step and the third step.
why should y be  yScale(d.y0) + yScale(d.y) - h,
and why should height be h - yScale(d.y)?
If these values are modified to different value(such as y be (yScale(d.y0) + yScale(d.y))/10  or so), desired graph are not shown.
Answer: The reason for this "reverse math" (as Scott Murray says in his code) is that in your first code, the upside down one, both the SVG coordinates system and the range have the Y coordinate growing from top to bottom (zero is located at the top and max value at the bottom). But when you reverse the range to ([h, 0]) in the second code, the SVG coordinates system continues to have Y coordinate growing from top to bottom, despite the range now going upwards.
In the "upside down" code, the top of the bar is actually its base and its height goes down, together with the SVG system. But in the second code, the "normal" chart, things are more complicated: the "base" of the bar is not its "y" attribute anymore, and the height value adds pixels downwards, regardless the inverted range. The SVG's coordinates system is not automagically inverted just because we inverted the range.
It's complicated, so let me rephrase it: in the SVG coordinates system, the "y" attribute is always the top of the rectangle. In your first code, the top of the rectangle is the base of the bar... but, in your second code, the top of the rectangle is the top of the bar. Confusing, I know.
Let's do a simple math: imagine a SVG with 100 pixels of height and a single bar with 80 pixels of height (y0: 0, y:80). To draw this bar, "y" attribute must set its top. How to calculate it? yScale(d.y0) gives us 100, and yScale(d.y) gives us 20. By adding them we have 120, which minus 100 (the height) gives us 20, the position of the top. Why not simply using d.y straight away? It can work for the first bar, but it won't for the subsequent ones.
Now the height, which must be 80 pixels. yScale(d.y) gives us 20, so, 100 (height) minus 20 gives us 80... and this goes for each bar.


Taxonomy autocomplete is empty because of access control for anonymous users

Question: I am using Finder, a great module for autocomplete searches. I am using it for autocompleting results from a taxonomy vocabulary. The way Finder works is it uses views for the autocomplete results. My view is a simple HTML list of all the terms from the vocabulary.
The taxonomy vocabulary is restricted only to logged in users. This causes the autocomplete to return empty results. I changed access settings in the view, but that didn't help.
Can anyone suggest a way around this?
I could simply redirect from the vocabulary path, but I'm not sure it's a good solution, since the data really needs to be private. How safe is it to just redirect?
Answer: Changing the access settings didn't help because Drupal filters out items that are not accessible by the user currently viewing the view.  There are a number of ways you can deal with this:

Use Vocabulary Permissions Per Role which gives finer grained control of taxonomies
Use Page Manager (part of ctools) to override the taxonomy page either by redirecting somewhere else or making your own page in Page Manager using Panels.
As you suggest, use a redirection module (or Rules perhaps) to redirect users away from the page.  The data will be safe as long as the rule or redirection fires before anything is rendered.


How do I insert HTML onto every page?

Question: I've got the following code in my module. I'm trying to get it to insert some HTML, ideally at the start of , but it seems that my call in hook_init() isn't working - what would be the right hook to call this in? I'm hoping it will just render slidedown.tpl.php after .
<?php
function slidedown_init() {
    drupal_add_js(drupal_get_path('module', 'slidedown') . '/slidedown.js');
    drupal_add_css(drupal_get_path('module', 'slidedown') . '/slidedown.css');
    slidedown_insert_html();
}

function slidedown_insert_html() {
    return theme('slidedown_template');
}

function slidedown_theme() {
    $themes = array (
        'slidedown_template' => array(
            'template' => 'slidedown', // your template file called slidedown.tpl.php
            'arguments' => array(),
        ),
    );
    return $themes;
}
?>

Answer: You probably want hook_page_build():
function slidedown_page_build (&$page) {
  $path = drupal_get_path('module', 'slidedown');

  drupal_add_js($path . '/slidedown.js');
  drupal_add_css($path . '/slidedown.css');

  $page['page_top']['slidedown_template'] = array(
    '#weight' => -1000,
    '#markup' => theme('slidedown_template'),
  );
}

I can't remember if that hook is too late to add JS and CSS.  You may need to put those in a template_preprocess_html().  That is a better choice that hook_init().
Answer: The template page.tpl.php and its variants define what is placed within the  tags.
It will probably be better to define a region in page.tpl.php and place it where you want. Then render your slideshow in this region.
For more information check out How the Drupal theme system works.

How do I insert HTML onto every page?


Retrospectively added some tags but git log A..B shows no commits

Question: My repo had the following tags:
2.2.1
2.0
1.4
1.3
1.2

I retrospectively added 0.0 and 1.0 tags using the following commands:
git checkout <SHA of some old commit>
git tag 1.0
git push origin tag 1.0

Now when I do the following on master
git log 1.2..1.0

there is no output.
Also, previously following was showing the correct output but now even that is empty
git log 2.2.1..2.0

Any help is appreciated.
Answer: If you are following common sense and lower version tags are placed before higher ones, you are asking to run log from a newer revision to an older one.... you should not expect to see much output there. Just like if you ran git log HEAD..HEAD~2... there will be nothing coming out of that.
Comment: yeah you're right, I totally didn't notice that! :/


Slab wise electricity bill calculation in Yii2

Question: I am working on yii2. I want to calculate electricity bill slab wise. For this, I have already inserted slabs and their respective rates in a table. Now I want to calculate it.
My units are 128.82 and below is my slab and their rates.

I am able to carry out the slabs by using the following query
$mData = \Yii::$app->db->createCommand("SELECT s.`slab_start`, s.`slab_end`, s.`rate`, r.`cust_id`
FROM `mdc_tariff_slabs` s
INNER JOIN `mdc_meter_cust_rel` r ON s.`t_id` = r.`tariff_id`
WHERE r.`cust_id` = $consumer_no")->queryAll();

array(3) { [0]=> array(3) { ["slab_start"]=> string(1) "1" ["slab_end"]=> string(3) "100" ["rate"]=> string(2) "10" } [1]=> array(3) { ["slab_start"]=> string(3) "101" ["slab_end"]=> string(3) "150" ["rate"]=> string(2) "12" } [2]=> array(3) { ["slab_start"]=> string(3) "151" ["slab_end"]=> NULL ["rate"]=> string(2) "14" } }

Note: The slabs may differ in future
I have tried the following code, set the slabs according to my requirements and tried to get the bill
 public static function calcBill($units)
{

    if($units < 100){
        $bill = $units*10;
    }elseif($units > 100 && $units <=150){
        $temp = 100*10;
        $remaining_units = $units - 100;
        $bill = $temp + ($remaining_units *12);
    }else{
        $temp = (100*10)+ (100*12);
        $remaining_units = $units - 150;
        $bill = $temp + ($remaining_units *14);
    }

    echo $bill;
    die();
}

The bill is 1345.84.
Now what I am trying to do is to pass the slabs as well and not to hard code them. I am finding it a bit difficult.
Update 1
I have 3 slabs/units limit. Each slab has its own rate. Rate is used to calculate the bill. Below is the scenario.

if units are <= 100 then charge Rs 10 rupee/unit
if units are > 100 && <= 150 then charge Rs 12 rupee/unit
if units are > 150 then charge Rs 14 rupee/unit

In my array, I have all the three values except for the last one which has only slab_start and rate.
By hard coding the slabs and rate I can calculate the bill but I want to calculate while using the array.
So the code may be look likes
if($units < slab_end){
        $bill = $units*rate;
    }elseif($units > slab_start && $units <=slab_end){<=slab_end
        $temp = prev_slab_start *rate;
        $remaining_units = $units - prev_slab;
        $bill = $temp + ($remaining_units *rate);
    }else{
        $temp = (prev_slab*10)+ (prev_slab*12);
        $remaining_units = $units - slab_start;
        $bill = $temp + ($remaining_units *14);
    }

I don't know the above logic is correct or not.
Note: Slab range and quantity may be changed. So I want to have a generic function that will do the needful
Update 2
Following the solution mentioned.
 $array = ArrayHelper::map($mData, 'slab_end', 'rate');

var_dump($array);
die();

The above gives me
array(3) { [100]=> string(2) "10" [150]=> string(2) "12" [""]=> string(2) "14" }

Then I have added a function
 public function billCalc($input, $slabs)
{
    $result = [];
    $bill = 0;
    $previous_slab = 0;

    foreach($slabs as $slab => $rate)
    {

        // calculate distance between current and previous slab
        $slab_distance = $slab - $previous_slab;
        // if current remainder of input value is >= distance, add distance to result,
        // and subtract distance from remainder of input
        if( $input >= $slab_distance )
        {
            $result[] = $slab_distance;
            $bill += $slab_distance * $rate;
            $input -= $slab_distance;
        }// otherwise, add remainder as last item of result, and break out of the loop here
        else
            {
            $result[] = $input;
            $bill += $input * $rate;
            break;
        }
        $previous_slab = $slab;
    }
    var_dump($result, $bill);
    exit();
}

Now I am facing an issue. When the input is less than 150 the result is perfectly ok, but when it's greater or equal to 150 I am getting below error

A non-numeric value encountered

It's giving me this error at
$slab_distance = $slab - $previous_slab;
Any help would be highly appreciated.
Comment: As if I did not just give you a solution for that under your previous question, which you asked not even an hour ago …? https://stackoverflow.com/questions/63069762/php-separate-string
Comment: Apparently with the rates, this is supposed to be different here, or at least a more complex calculation/formula, according to the discussion below https://stackoverflow.com/a/63070039/1427878 But this still lacks a _proper_ explanation of how your rates are supposed to figure into the calculation, IMHO. Explain that using your _words_, please, instead of going, "here is code, you figure it out".
Answer: So you simply want to multiply the amount covered by each slab ("units") with the rate then - so I would create an array that has the slab end as key, and the rate as value - then you can simply loop over that with the extended foreach syntax, and have access to the rate corresponding to the slab at all times.
Expanding on my answer to the previous question, this would look like this then:
$input = '128.82';
$slabs = [100 => 10, 150 => 12, PHP_INT_MAX => 14];

$result = [];
$bill = 0;
$previous_slab = 0;

foreach($slabs as $slab => $rate) {
  // calculate distance between current and previous slab
  $slab_distance = $slab - $previous_slab;
  // if current remainder of input value is >= distance, add distance to result,
  // and subtract distance from remainder of input
  if( $input >= $slab_distance ) {
    $result[] = $slab_distance;
    $bill += $slab_distance * $rate;
    $input -= $slab_distance;
  }
  // otherwise, add remainder as last item of result, and break out of the loop here
  else {
    $result[] = $input;
    $bill += $input * $rate;
    break;
  }
  $previous_slab = $slab;
}

var_dump($result, $bill);

Result:
array (size=2)
  0 => int 100
  1 => float 28.82

float 1345.84

My approach again uses only the upper slab boundaries here - you don't have one in your last record from the database, so I am substituting PHP_INT_MAX here for that NULL value. Taking that into account, when you create that array from your database content, should be not challenge, I hope.
(If you only need the 1345.84 as result here, and not the array that shows the distribution accross the indivudual slabs, then you can just remove all lines that contain $result anywhere.)
Comment: how can I convert `array(3) { [0]=> array(3) { ["slab_start"]=> string(1) "1" ["slab_end"]=> string(3) "100" ["rate"]=> string(2) "10" } [1]=> array(3) { ["slab_start"]=> string(3) "101" ["slab_end"]=> string(3) "150" ["rate"]=> string(2) "12" } [2]=> array(3) { ["slab_start"]=> string(3) "151" ["slab_end"]=> NULL ["rate"]=> string(2) "14" } }
` to `[100 => 10, 150 => 12, PHP_INT_MAX => 14];`
Comment: Also, how will it work `N` number of slabs and rates? To mention the last slab will only have `slab_start` and `rate`
Comment: I am facing an issue. Kindly check my `update 2`
Comment: An empty string, and `PHP_INT_MAX`, are not the same thing. We want to be able to use those key values for mathematical operations here, so you can not just use `''` as the key here.
Comment: How can I then put `PHP_INT_MAX` in my array ?
Comment: You asked about that already, https://stackoverflow.com/questions/63078251/yii2-associative-array - why did you accept the answer there, when it does not even do what you want? Plus, figuring out this minor part of the whole thing, don't you think that is something you should be able to handle yourself, maybe?
Comment: Even with hardcoding the `NULL` part with `PHP_INT_MAX` or some other flag. I am still getting the error.
Comment: Well then you probably "hardcoded" it wrong … what response do you expect, when you only give this little _useful_ information?
Comment: I have hardcoded it in my table. then I tried to fetch the data and map them accordingly which gives me `array(3) { [100]=> string(2) "10" [150]=> string(2) "12" ["PHP_INT_MAX"]=> string(2) "14" }`
Comment: `"PHP_INT_MAX"` and `PHP_INT_MAX` are two different things. You need to either _replace_ the NULL value with the _actual_ value of `PHP_INT_MAX` - or you could just set a high enough integer value instead of NULL in your database table to begin with.
Comment: Ok let me have a try. Thanks for the help


Rails extending Date class

Question: I have created a file lib/ext/date.rb which extends the Date class with a method.
class Date
  def self.next_(weekday_string)
    // code here
  end
end

In my application.rb file I autoload everything in this ext folder
config.autoload_paths << "#{Rails.root}/lib/ext"

But I keep getting the error undefined method next_ for Date:Class
Calling this method from within the console works fine
load 'lib/ext/date.rb'; Date.next_('wednesday')
=> Wed, 07 Oct 2015

And yes, the server has been restarted before trying to use this extended method.
Comment: Wouldn't this be a better name for your method `def self.next(weekday)`?
Comment: It would be :) It used to be called `next_weekday` but I removed weekday. Not sure why I left the `_`
Comment: Did you restarted the Rails Server ?
Comment: Check the last line of the question @LukyBoy-KU
Answer: I guess, your understanding of Rails autoload mechanism is fuzzy.
autoload_paths is used when rails tries to resolve undefined constant. Say, you access a User for the first time. No such class is loaded, so rails will look in its autoload paths and try find User there.
Your case is different. Date is certain to be present (as it is a system class). And thus rails will have no reason to access files in autoload paths.
Solution:
load the files explicitly. For example, in an initializer
# 00_monkey_patching.rb
Dir["#{Rails.root}/lib/monkey_patching/*.rb"].each do |file|
  require file
end

Comment: Yes, you need to explicitly load it. Perhaps, in an initializer.
Comment: So I need to specifically load this class in?
Comment: @CarlMarkham, also, [check out this guide](http://stackoverflow.com/a/5654580/2235594) to extend core classes. I find the solution more elegant than using `monkey_patching` as a folder name.
Comment: @TheCha͢mp: using monkey_patching describes the purpose very well. That's what you do, patch stuff. If you need to patch, say, Mongoid driver, then `core_ext` would be a misleading name (because mongoid is not "core"). Also, the only different thing here is the folder name. So it's at the same level of elegance. :)
Comment: @TheCha͢mp: RE "genius" solution: it requires 3 lines less code, that's all. But drawbacks may be significant. Now your patches are scattered through the initializers folder. What if some of your other non-patching initializers rely on some patch, but that patch is not yet loaded at this point, due to lexicographical sorting?
Comment: Ye you got your points... :) Anyway, it was helpful since I learnt something new from you.
Comment: I agree an initializer is probably the most appropriate place for something like this.

Rails extending Date class


System.Reflection.TargetInvocationException error (C#)

Question: I am trying to get an information from the web (adress in my code) with HtmlAgilityPack in C#, but I have to wait until the
 is loaded on the page.
When I execute this code :
    var url = $"https://www.website.com/";
    var web = new HtmlWeb();
    var doc = web.LoadFromBrowser(url, html =>
    {
        return !html.Contains("

");
    });
    string adress = doc.DocumentNode
          .SelectSingleNode("//td/span[@id='testedAddress")
          .Attributes["value"].Value;
    Console.WriteLine("Voici l'adresse :",adress);

I always get this error :

Translation :  System.Reflection.TargetInvocationException: 'An exception has been raised by the target of an appeal.'

ThreadStateException: Can not instantiate ActiveX control
  '8856f961-340a-11d0-a96b-00c04fd705a2', because the current thread is
  not a partitioned thread (STA, Single-Threaded Apartment).

How can I get rid of this error ?
Comment: Are you by any chance running this code in a separate Thread?
Comment: No, all my code is in one thread
Comment: That's odd, usually this only happens when you try to use UI components in a non STA-Thread.
Comment: Try setting the thread apartment to STA in your Main() [STAThread]
Comment: @Lulucmy Is this a console application?
Comment: Yes a console app

and @Oscar I don't know how to do that...
Comment: @Lulucmy https://stackoverflow.com/a/13825951/3214843
Comment: @Lulucmy if that solves you problem, please accept Oscars answer below.
Answer: Apply STAThreadAttribute to your Main function:
 [STAThread]
 static void Main(string[] args)
 {
     //Your code here
 }


Arima Model with weekday dummy variables Forecast

Question: I'm trying to create an Arima model and forecast it ahead the next 20 hours using the code and data below.
When I look at the median of df$tri for each hour and broken down by day of the week, each weekday seems to have a distinct 24 hour pattern.
So I thought I would try adding dummy variables for the day of the week to my model as xreg predictors.
When I plot Acast$mean, I'm just getting a flat line.  So I was wondering if there was something incorrect about the way I'm creating and using the dummy variables for day of the week.
Code:
##BoxCox

Tlambda <- BoxCox.lambda(df$Tri)

##Partitioning Time Series

EndTrain<-336
ValStart<-EndTrain+1
ValEnd<-ValStart+20

tsTrain <-df$Tri[1:EndTrain]
tsValidation<-df$Tri[ValStart:ValEnd]

##Weekday variables
Copydf<-df
Copydf$Weekday<-as.factor(weekdays(as.Date(Copydf$DateTime, "%Y-%m-%d")))
Weekdays <- Copydf$Weekday[1:nrow(Copydf)]
xreg1 <- model.matrix(~as.factor(Weekdays)+0)[, 1:7]
colnames(xreg1) <- c("Friday", "Monday", "Saturday", "Sunday","Thursday","Tuesday","Wednesday")

xreg1Train<-xreg1[1:EndTrain,]
xreg1Val<-xreg1[ValStart:ValEnd,]

##Checking effect of Weekday
Arima.fit <- auto.arima(tsTrain, lambda = Tlambda, xreg=xreg1Train, stepwise=FALSE, approximation = FALSE )

##Forecast

Acast<-forecast(Arima.fit,xreg=xreg1Val, h=20)

Acast$mean

Data:
    dput(df$Tri[1:336])
c(11, 14, 17, 5, 5, 5.5, 8, NA, 5.5, 6.5, 8.5, 4, 5, 9, 10, 11,
7, 6, 7, 7, 5, 6, 9, 9, 6.5, 9, 3.5, 2, 15, 2.5, 17, 5, 5.5,
7, 6, 3.5, 6, 9.5, 5, 7, 4, 5, 4, 9.5, 3.5, 5, 4, 4, 9, 4.5,
6, 10, NA, 9.5, 15, 9, 5.5, 7.5, 12, 17.5, 19, 7, 14, 17, 3.5,
6, 15, 11, 10.5, 11, 13, 9.5, 9, 7, 4, 6, 15, 5, 18, 5, 6, 19,
19, 6, 7, 7.5, 7.5, 7, 6.5, 9, 10, 5.5, 5, 7.5, 5, 4, 10, 7,
5, 12, 6, NA, 4, 2, 5, 7.5, 11, 13, 7, 8, 7.5, 5.5, 7.5, 15,
7, 4.5, 9, 3, 4, 6, 17.5, 11, 7, 6, 7, 4.5, 4, 4, 5, 10, 14,
7, 7, 4, 7.5, 11, 6, 11, 7.5, 15, 23.5, 8, 12, 5, 9, 10, 4, 9,
6, 8.5, 7.5, 6, 5, 8, 6, 5.5, 8, 11, 10.5, 4, 6, 7, 10, 11.5,
11.5, 3, 4, 16, 3, 2, 2, 8, 4.5, 7, 4, 8, 11, 6.5, 7.5, 17, 6,
6.5, 9, 12, 17, 10, 5, 5, 9, 3, 8.5, 11, 4.5, 7, 16, 11, 14,
6.5, 15, 8.5, 7, 6.5, 11, 2, 2, 13.5, 4, 2, 16, 11.5, 3.5, 9,
16.5, 2.5, 4.5, 8.5, 5, 6, 7.5, 9.5, NA, 9.5, 8, 2.5, 4, 12,
13, 10, 4, 6, 16, 16, 13, 8, 12, 19, 19, 5.5, 8, 6.5, NA, NA,
NA, 15, 12, NA, 6, 11, 8, 4, 2, 3, 4, 10, 7, 5, 4.5, 4, 5, 11.5,
12, 10.5, 4.5, 3, 4, 7, 15.5, 9.5, NA, 9.5, 12, 13.5, 10, 10,
13, 6, 8.5, 15, 16.5, 9.5, 14, 9, 9.5, 11, 15, 14, 5.5, 6, 14,
16, 9.5, 23, NA, 19, 12, 5, 11, 16, 8, 11, 9, 13, 6, 7, 3, 5.5,
7.5, 19, 6.5, 5.5, 4.5, 7, 8, 7, 10, 11, 13, NA, 12, 1.5, 7,
7, 12, 8, 6, 9, 15, 9, 3, 5, 11, 11, 8, 6, 3, 7.5)

    dput(df$DateTime[1:336])
c("2015-01-01 00:00", "2015-01-01 01:00", "2015-01-01 02:00",
"2015-01-01 03:00", "2015-01-01 04:00", "2015-01-01 05:00", "2015-01-01 06:00",
"2015-01-01 07:00", "2015-01-01 08:00", "2015-01-01 09:00", "2015-01-01 10:00",
"2015-01-01 11:00", "2015-01-01 12:00", "2015-01-01 13:00", "2015-01-01 14:00",
"2015-01-01 15:00", "2015-01-01 16:00", "2015-01-01 17:00", "2015-01-01 18:00",
"2015-01-01 19:00", "2015-01-01 20:00", "2015-01-01 21:00", "2015-01-01 22:00",
"2015-01-01 23:00", "2015-01-02 00:00", "2015-01-02 01:00", "2015-01-02 02:00",
"2015-01-02 03:00", "2015-01-02 04:00", "2015-01-02 05:00", "2015-01-02 06:00",
"2015-01-02 07:00", "2015-01-02 08:00", "2015-01-02 09:00", "2015-01-02 10:00",
"2015-01-02 11:00", "2015-01-02 12:00", "2015-01-02 13:00", "2015-01-02 14:00",
"2015-01-02 15:00", "2015-01-02 16:00", "2015-01-02 17:00", "2015-01-02 18:00",
"2015-01-02 19:00", "2015-01-02 20:00", "2015-01-02 21:00", "2015-01-02 22:00",
"2015-01-02 23:00", "2015-01-03 00:00", "2015-01-03 01:00", "2015-01-03 02:00",
"2015-01-03 03:00", "2015-01-03 04:00", "2015-01-03 05:00", "2015-01-03 06:00",
"2015-01-03 07:00", "2015-01-03 08:00", "2015-01-03 09:00", "2015-01-03 10:00",
"2015-01-03 11:00", "2015-01-03 12:00", "2015-01-03 13:00", "2015-01-03 14:00",
"2015-01-03 15:00", "2015-01-03 16:00", "2015-01-03 17:00", "2015-01-03 18:00",
"2015-01-03 19:00", "2015-01-03 20:00", "2015-01-03 21:00", "2015-01-03 22:00",
"2015-01-03 23:00", "2015-01-04 00:00", "2015-01-04 01:00", "2015-01-04 02:00",
"2015-01-04 03:00", "2015-01-04 04:00", "2015-01-04 05:00", "2015-01-04 06:00",
"2015-01-04 07:00", "2015-01-04 08:00", "2015-01-04 09:00", "2015-01-04 10:00",
"2015-01-04 11:00", "2015-01-04 12:00", "2015-01-04 13:00", "2015-01-04 14:00",
"2015-01-04 15:00", "2015-01-04 16:00", "2015-01-04 17:00", "2015-01-04 18:00",
"2015-01-04 19:00", "2015-01-04 20:00", "2015-01-04 21:00", "2015-01-04 22:00",
"2015-01-04 23:00", "2015-01-05 00:00", "2015-01-05 01:00", "2015-01-05 02:00",
"2015-01-05 03:00", "2015-01-05 04:00", "2015-01-05 05:00", "2015-01-05 06:00",
"2015-01-05 07:00", "2015-01-05 08:00", "2015-01-05 09:00", "2015-01-05 10:00",
"2015-01-05 11:00", "2015-01-05 12:00", "2015-01-05 13:00", "2015-01-05 14:00",
"2015-01-05 15:00", "2015-01-05 16:00", "2015-01-05 17:00", "2015-01-05 18:00",
"2015-01-05 19:00", "2015-01-05 20:00", "2015-01-05 21:00", "2015-01-05 22:00",
"2015-01-05 23:00", "2015-01-06 00:00", "2015-01-06 01:00", "2015-01-06 02:00",
"2015-01-06 03:00", "2015-01-06 04:00", "2015-01-06 05:00", "2015-01-06 06:00",
"2015-01-06 07:00", "2015-01-06 08:00", "2015-01-06 09:00", "2015-01-06 10:00",
"2015-01-06 11:00", "2015-01-06 12:00", "2015-01-06 13:00", "2015-01-06 14:00",
"2015-01-06 15:00", "2015-01-06 16:00", "2015-01-06 17:00", "2015-01-06 18:00",
"2015-01-06 19:00", "2015-01-06 20:00", "2015-01-06 21:00", "2015-01-06 22:00",
"2015-01-06 23:00", "2015-01-07 00:00", "2015-01-07 01:00", "2015-01-07 02:00",
"2015-01-07 03:00", "2015-01-07 04:00", "2015-01-07 05:00", "2015-01-07 06:00",
"2015-01-07 07:00", "2015-01-07 08:00", "2015-01-07 09:00", "2015-01-07 10:00",
"2015-01-07 11:00", "2015-01-07 12:00", "2015-01-07 13:00", "2015-01-07 14:00",
"2015-01-07 15:00", "2015-01-07 16:00", "2015-01-07 17:00", "2015-01-07 18:00",
"2015-01-07 19:00", "2015-01-07 20:00", "2015-01-07 21:00", "2015-01-07 22:00",
"2015-01-07 23:00", "2015-01-08 00:00", "2015-01-08 01:00", "2015-01-08 02:00",
"2015-01-08 03:00", "2015-01-08 04:00", "2015-01-08 05:00", "2015-01-08 06:00",
"2015-01-08 07:00", "2015-01-08 08:00", "2015-01-08 09:00", "2015-01-08 10:00",
"2015-01-08 11:00", "2015-01-08 12:00", "2015-01-08 13:00", "2015-01-08 14:00",
"2015-01-08 15:00", "2015-01-08 16:00", "2015-01-08 17:00", "2015-01-08 18:00",
"2015-01-08 19:00", "2015-01-08 20:00", "2015-01-08 21:00", "2015-01-08 22:00",
"2015-01-08 23:00", "2015-01-09 00:00", "2015-01-09 01:00", "2015-01-09 02:00",
"2015-01-09 03:00", "2015-01-09 04:00", "2015-01-09 05:00", "2015-01-09 06:00",
"2015-01-09 07:00", "2015-01-09 08:00", "2015-01-09 09:00", "2015-01-09 10:00",
"2015-01-09 11:00", "2015-01-09 12:00", "2015-01-09 13:00", "2015-01-09 14:00",
"2015-01-09 15:00", "2015-01-09 16:00", "2015-01-09 17:00", "2015-01-09 18:00",
"2015-01-09 19:00", "2015-01-09 20:00", "2015-01-09 21:00", "2015-01-09 22:00",
"2015-01-09 23:00", "2015-01-10 00:00", "2015-01-10 01:00", "2015-01-10 02:00",
"2015-01-10 03:00", "2015-01-10 04:00", "2015-01-10 05:00", "2015-01-10 06:00",
"2015-01-10 07:00", "2015-01-10 08:00", "2015-01-10 09:00", "2015-01-10 10:00",
"2015-01-10 11:00", "2015-01-10 12:00", "2015-01-10 13:00", "2015-01-10 14:00",
"2015-01-10 15:00", "2015-01-10 16:00", "2015-01-10 17:00", "2015-01-10 18:00",
"2015-01-10 19:00", "2015-01-10 20:00", "2015-01-10 21:00", "2015-01-10 22:00",
"2015-01-10 23:00", "2015-01-11 00:00", "2015-01-11 01:00", "2015-01-11 02:00",
"2015-01-11 03:00", "2015-01-11 04:00", "2015-01-11 05:00", "2015-01-11 06:00",
"2015-01-11 07:00", "2015-01-11 08:00", "2015-01-11 09:00", "2015-01-11 10:00",
"2015-01-11 11:00", "2015-01-11 12:00", "2015-01-11 13:00", "2015-01-11 14:00",
"2015-01-11 15:00", "2015-01-11 16:00", "2015-01-11 17:00", "2015-01-11 18:00",
"2015-01-11 19:00", "2015-01-11 20:00", "2015-01-11 21:00", "2015-01-11 22:00",
"2015-01-11 23:00", "2015-01-12 00:00", "2015-01-12 01:00", "2015-01-12 02:00",
"2015-01-12 03:00", "2015-01-12 04:00", "2015-01-12 05:00", "2015-01-12 06:00",
"2015-01-12 07:00", "2015-01-12 08:00", "2015-01-12 09:00", "2015-01-12 10:00",
"2015-01-12 11:00", "2015-01-12 12:00", "2015-01-12 13:00", "2015-01-12 14:00",
"2015-01-12 15:00", "2015-01-12 16:00", "2015-01-12 17:00", "2015-01-12 18:00",
"2015-01-12 19:00", "2015-01-12 20:00", "2015-01-12 21:00", "2015-01-12 22:00",
"2015-01-12 23:00", "2015-01-13 00:00", "2015-01-13 01:00", "2015-01-13 02:00",
"2015-01-13 03:00", "2015-01-13 04:00", "2015-01-13 05:00", "2015-01-13 06:00",
"2015-01-13 07:00", "2015-01-13 08:00", "2015-01-13 09:00", "2015-01-13 10:00",
"2015-01-13 11:00", "2015-01-13 12:00", "2015-01-13 13:00", "2015-01-13 14:00",
"2015-01-13 15:00", "2015-01-13 16:00", "2015-01-13 17:00", "2015-01-13 18:00",
"2015-01-13 19:00", "2015-01-13 20:00", "2015-01-13 21:00", "2015-01-13 22:00",
"2015-01-13 23:00", "2015-01-14 00:00", "2015-01-14 01:00", "2015-01-14 02:00",
"2015-01-14 03:00", "2015-01-14 04:00", "2015-01-14 05:00", "2015-01-14 06:00",
"2015-01-14 07:00", "2015-01-14 08:00", "2015-01-14 09:00", "2015-01-14 10:00",
"2015-01-14 11:00", "2015-01-14 12:00", "2015-01-14 13:00", "2015-01-14 14:00",
"2015-01-14 15:00", "2015-01-14 16:00", "2015-01-14 17:00", "2015-01-14 18:00",
"2015-01-14 19:00", "2015-01-14 20:00", "2015-01-14 21:00", "2015-01-14 22:00",
"2015-01-14 23:00")

Answer: To start with we will explore different ways that repeating patterns can appear in time series data and how we can model those patterns.  This may be over kill for the question, however I do think that this answer will help you think about what is happening in the models and design better experiments to model your data going forward.
Simple daily seasonality
To begin with, lets think about a daily seasonal ARIMA model.  This type of model is looking for some type of pattern that repeats where we see the same thing every day.  A time series that this type of model might work well for might look like this:
set.seed(0)
# create a pattern that repeats every 24 hours
daily <- sinpi(seq(1, 3 - 1/24, length.out = 24))
# create a time series out of that repeating pattern 2 weeks long
dailyseas <- ts(rep(daily, 14), frequency = 24)
# add some noise to the data to make it interesting to fit
dailyseas <- dailyseas + rnorm(length(dailyseas), sd = 0.2)
plot(dailyseas, main = "Daily Repeating Pattern")

We can then fit a seasonal AR model to the data and get a pretty good forecast for the series.  Since we know that the pattern is pretty stable over time, I will use two seasonal lags rather than just one because this will allow the model to smooth out any noise in the data better.
> (dsmodel <- arima(dailyseas, seasonal = c(2L, 0L, 0L)))

Call:
arima(x = dailyseas, seasonal = c(2L, 0L, 0L))

Coefficients:
        sar1    sar2  intercept
      0.4254  0.5396     0.0094
s.e.  0.0455  0.0465     0.1368

sigma^2 estimated as 0.05491:  log likelihood = -20.56,  aic = 49.13

This is just about perfect, the intercept is near zero, which it should be, and the sum of the coefficients on the seasonal lags is close to 1, meaning the forecast is about an average of them (eg. we predict the value tomorrow at noon is about the average of today and yesterday at noon).  It is important to note we let the ARIMA model know how often the pattern repeated itself by making a ts object and setting the frequency = 24.  Alternatively, we could have used a vector for the series and set seasonal = list(order = c(1L, 0L, 0L), period = 24).
This works well when we have a simple repeating pattern, but what if we have a day of week effect.
Daily Seasonality with a Day of Week effect
A day of week effect is an consistant impact on the underlying series we see based on the day of the week.  We can add a day of week effect to our data using:
# Create an adjustment for day of week: we will leave Monday as 0
# so later it is easy to see the change in other days relative to
# Monday.
(doweffect <- c(0 , sample(c(-3, -2, -1, 1, 2, 3))))
# add our day of week effect to the original series
dowseas <- dailyseas + rep(doweffect, 2, each = 24)
plot(dowseas)

We handle this new pattern in our data in one of two ways 1) adding external regressors to our original ARIMA model or 2) thinking of the weekly repeating pattern in the data as the new seasonality of the data.  In an ARIMA model with external regressors, we are looking for some sort of ARIMA type pattern that is "thrown off" by some amount by the things quantified by the external regressors.  In the model with weekly seasonality, we are looking for the interaction of the daily and weekly pattern and ignoring that the daily pattern is still present in each day of the week.  Below we create the original seasonal model as well as the 2 variants.
# Creates a model matrix to indicate the day of week for values in
# our time series.  Note the model matrix does not have a column to
# indicate Monday.  The purpose of the model matrix is to allow the
# model to include the impact of a value relative to some baseline,
# usually the first factor level; in this case, Monday.  We also
# remove the intercept term since intercept is already part of the
# ARIMA models.
> dowreg <- model.matrix(~as.factor(rep(1:7, 2, each = 24)))[, -1]
> colnames(dowreg) <- c("Tues", "Weds", "Thurs", "Fri", "Sat", "Sun")
# Creates a first model where the day of week is ignored
> (dowsmodel <- arima(dowseas, seasonal = c(2L, 0L, 0L)))

Call:
arima(x = dowseas, seasonal = c(2L, 0L, 0L))

Coefficients:
        sar1     sar2  intercept
      0.1085  -0.1550     0.0170
s.e.  0.0588   0.0612     0.1123

sigma^2 estimated as 4.455:  log likelihood = -728.46,  aic = 1464.93

Hmm, that doesn't look great, our intercept is near zero and our seasonal coefficients are nearly canceling each other out. Lets look at our external regressor model:
# Creates a model where the day of week effect is accounted for using
# an external regressor
> (dowxreg <- arima(dowseas, seasonal = c(2L, 0L, 0L), xreg = dowreg))

Call:
arima(x = dowseas, seasonal = c(2L, 0L, 0L), xreg = dowreg)

Coefficients:
        sar1    sar2  intercept    Tues    Weds    Thurs      Fri      Sat     Sun
      0.4301  0.5351    -0.0080  1.0376  2.0036  -0.9759  -1.9841  -3.0051  3.0363
s.e.  0.0459  0.0468     0.1389  0.0394  0.0360   0.0424   0.0427   0.0413  0.0438

sigma^2 estimated as 0.05457:  log likelihood = -19.51,  aic = 59.01

This is much better, the two seasonal lags (sar1 and sar2) are basically taking an average again like they did in our other model, and the external regressors are adjusting the days by the correct amount (1 for Tues, 2 for Weds, -1 for Thurs, -2 for Fri, -3 for Sat and 3 for Sun).  How about our weekly seasonal model:
# Creates a model where the day of week effect is accounted for by
# increasing the seasonality to weekly rather than daily.  This time
# we can only use 1 seasonal lag because our data only don't have
# enough seasonal periods at the weekly frequency.
> (dowlongs <- arima(dowseas, seasonal = list(order = c(1L, 0L, 0L),
+                                             period = 24*7)))

Call:
arima(x = dowseas, seasonal = list(order = c(1L, 0L, 0L), period = 24 * 7))

Coefficients:
      sar1  intercept
         1      0.005
s.e.   NaN   1400.371

sigma^2 estimated as 0.03082:  log likelihood = -8.64,  aic = 23.27

Once again, this looks good, it is predicting next Monday at noon should be the same as last Monday at noon, which makes sense for this data.  Lets look at how this turns out in the forecasts:
par(mfrow = c(1,1))
plot(forecast(dowsmodel, 48), PI = FALSE, xlim = c(8, 17),
     main = "Forecasts from Various Seasonal AR models")
lines(forecast(dowxreg, 48, xreg = dowreg[1:48, ])$mean, col = "red", lwd = 2)
lines(forecast(dowlongs, 48)$mean, col = "green", lwd = 2)
abline(v = 8, lty = 2)
legend("topleft", bty = "n",
       c("Seasonal AR", "Seasonal AR with DoW", "Long Seasonal AR"),
       fill = c("blue", "red", "green"))

While the original mode that worked so well before falls apart, we see that both of the other approaches work well for this new data.  The model with external regressors is able to find the daily pattern that is occurring once it takes into account the effect of the day of week.  The weekly seasonal model is missing the daily pattern, but is able to overcome that by seeing the larger pattern that repeats every week.
Distinct pattern for each day of the week
Now we are finally going to get into what you claim to see in your data; a daily pattern which is different for each day of the week.  We can make a series with this property as follows:
# Creates a time series where each day of week has a unique pattern
dailysig <- c(daily,
              sort(daily),
              sort(daily, decreasing = TRUE),
              abs(daily),
              exp(daily),
              log(daily + 2),
              cos(daily))
# Creates a two week long version of this series with a noise component
diffdaily <- ts(rep(dailysig, 2), frequency = 24)
diffdaily <- diffdaily + rnorm(length(diffdaily), sd = 0.2)
plot(diffdaily, main = "Unique Pattern for Each Day of Week")

We see that Monday's pattern doesn't really look like Tuesday's or Wednesday's etc.  Lets examine what happens if we try and make each of our 3 types of models for this data set.
# Makes the same three models as last time
> (dowsmodel <- arima(diffdaily, seasonal = c(2L, 0L, 0L)))

Call:
arima(x = diffdaily, seasonal = c(2L, 0L, 0L))

Coefficients:
        sar1     sar2  intercept
      0.2488  -0.2669     0.4651
s.e.  0.0533   0.0537     0.0390

sigma^2 estimated as 0.509:  log likelihood = -365.57,  aic = 739.14

> (dowxreg <- arima(diffdaily, seasonal = c(2L, 0L, 0L), xreg = dowreg))

Call:
arima(x = diffdaily, seasonal = c(2L, 0L, 0L), xreg = dowreg)

Coefficients:
        sar1     sar2  intercept     Tues     Weds   Thurs     Fri     Sat     Sun
      0.0756  -0.3189     0.0224  -0.0670  -0.0105  0.5791  1.1814  0.6315  0.7423
s.e.  0.0531   0.0532     0.0875   0.1205   0.1419  0.1241  0.1199  0.1325  0.1234

sigma^2 estimated as 0.3413:  log likelihood = -298.76,  aic = 617.52

> (dowlongs <- arima(diffdaily, seasonal = list(order = c(1L, 0L, 0L), period = 24*7)))

Call:
arima(x = diffdaily, seasonal = list(order = c(1L, 0L, 0L), period = 24 * 7))

Coefficients:
        sar1  intercept
      0.9254     0.4591
s.e.  0.0111     0.0575

sigma^2 estimated as 0.08293:  log likelihood = -221.5,  aic = 448.99

> plot(forecast(dowsmodel, 48), PI = FALSE, xlim = c(8, 17),
+      main = "Forecasts from Various Seasonal AR models for Different DoW Effects")
> lines(forecast(dowxreg, 48, xreg = dowreg[1:48, ])$mean, col = "red", lwd = 2)
> lines(forecast(dowlongs, 48)$mean, col = "green", lwd = 2)
> abline(v = 8, lty = 2)
> legend("topleft", bty = "n",
+        c("Seasonal AR", "Seasonal AR with DoW", "Long Seasonal AR"),
+        fill = c("blue", "red", "green"))

Results fell apart for the first two models this time.  Since there isn't an underlying daily pattern any more, the model with external regressors was only able to see that certain days of the week are higher or lower on average, but the pattern from hour to hour was missed.  The weekly seasonal model however was still about to see the weekly repeat and make a reasonable model.
Your Data
Now that we have seen the importance of seasonality in our models, lets see what happens if we try running auto.arima again, but this time making your data a seasonal time series.
> tsTrain <- ts(tsTrain, frequency = 24)
> (dowsmodel <- auto.arima(tsTrain))
Series: tsTrain
ARIMA(0,0,0)(1,0,0)[24] with non-zero mean

Coefficients:
        sar1    mean
      0.0508  8.4899
s.e.  0.0579  0.2452

sigma^2 estimated as 17.31:  log likelihood=-928.96
AIC=1863.91   AICc=1863.98   BIC=1875.36
> (dowxreg <- auto.arima(tsTrain, xreg = dowreg))
Series: tsTrain
Regression with ARIMA(0,0,0)(1,0,0)[24] errors

Coefficients:
        sar1  intercept     Tues    Weds   Thurs     Fri     Sat     Sun
      0.0841     7.7401  -0.4165  2.3504  0.0211  1.1671  1.8975  0.3029
s.e.  0.0587     0.5991   0.8074  0.8496  0.8617  0.8520  0.8461  0.8288

sigma^2 estimated as 16.63:  log likelihood=-919.55
AIC=1857.1   AICc=1857.65   BIC=1891.45
> (dowlongs <- auto.arima(ts(tsTrain, frequency = 24*7)))
Series: ts(tsTrain, frequency = 24 * 7)
ARIMA(0,0,2) with non-zero mean

Coefficients:
         ma1      ma2    mean
      0.2433  -0.0171  8.5118
s.e.  0.0583   0.0506  0.2782

sigma^2 estimated as 16.51:  log likelihood=-921.06
AIC=1850.12   AICc=1850.24   BIC=1865.39
> plot(forecast(dowsmodel, 24), PI = FALSE, xlim = c(8, 16),
+      main = "Forecasts from Various Seasonal AR models for Different DoW Effects")
> lines(forecast(dowxreg, 24, xreg = dowreg[1:24, ])$mean, col = "red", lwd = 2)
> lines(ts(forecast(dowlongs, 24)$mean, start = 15, frequency = 24),
+       col = "green", lwd = 2)
> abline(v = 8, lty = 2)
> legend("topleft", bty = "n",
+        c("Seasonal AR", "Seasonal AR with DoW", "Long Seasonal AR"),
+        fill = c("blue", "red", "green"))

The "each weekday seems to have a distinct 24 hour pattern" doesn't seem to be happening as seen by the trouble fitting a the weekly seasonal model, but there does seem to be a daily seasonality the models are picking up on since.  Personally, I would trust the plain seasonal model (no external regressors) the most since it is less prone to over fitting than the one with external regressors, but that is your call.  In general, you might feel disappointed since the forecasts don't look much like your data.  This is because there is a lot of noise in your data that the model still can't account for.
Conclusions

A seasonal model will allow your data to find repeating patterns in your data.
Adding external regressors to your model can allow the model to find the underlying pattern when the pattern is obscured by another influence.
If every day of the week has a different pattern, that is a weekly seasonality, not a day of week effect.
Comment: @IrishStat Do you mean an ARIMA model with two different seasonalities?  If so, that does sound appealing, but [I am not aware of any implementation for such a model](https://stats.stackexchange.com/questions/47729/two-seasonal-periods-in-arima-using-r) in the languages I am familiar with.  You could of course  use a different model like `tbats` which is based on exponential smoothing, but the OP was requesting an ARIMA based model.
Comment: i meant a deterministic  model with 1 + 6 + 23 predictors and then identifying/incorpoarating an approriate arima model and potential outliers/level shifts/seasonal pulses/time trends AND arma. IN this way the OP gets his arma strtcture bur it is integrated into needed deterministic structure, there is no double seasonality in ARIMA.
Comment: Why not add both daily effects and hourly effects and allow for unusual values to be detected and remedied with pulse indicators being added to the model where needed ?
Comment: @IrishStat I would hesitate to put a model with so many predictors on this size dataset.  In particular, if the pattern really does show a differently pattern every day of the week (which I am not convince it does), you would need 24*7 - 1 predictors to account for the fact that "2pm" has a different pattern on Monday than on Tuesday.  If you want to account for multiple seasonalities, I would be more inclined to [try including Fourier terms](https://robjhyndman.com/hyndsight/longseasonality/) to avoid parameter space explosion.
Comment: If you use 6 day-of-the-week and 23 hour of the day that's 29 = 1 for the constant. You can search/try to see what interaction series are significant )which essentially forms a minimally sufficient set . Then when you add any needed ARIMA structure you are home along with intervention detection to ferret out unusual values. I do this routinely with great results. .
Answer: Hyndman's docs say the xreg vector needs to have the same number of rows as the time series. In your code, where defining 'Weekdays' you are missing a comma before the closing square bracket.
If this external regressor approach doesn't work I'd try fitting a seasonal arima model with m=7 manually.


The "mode" of sum of dependent random variables

Question: Is there some study on finding the mode of sum of dependent random variales?
Or give some bounded zone for the mode?
Million thanks for your helps!
Answer: The mode is bounded within 3^(1/2) multiple of the standard deviation around the mean for unimodal continuous distributions.


C# Dealing with dictionaries where values MAY (or may not) be arrays

Question: I'm working on creating a library which decodes JSON objects into c# objects that our users can then access, modify and resend. Some objects are predetermined, others are going to end up being non-predetermined (Though they do have a several standard possible formats). So the best way we found of managing these values with this is to create an object with a dictionary in it.
Dictionary<string, Field> _fields = new Dictionary<string,Field>;

Then all our objects can be fields, we create properties for established objects and an indexer/method to get any field including the non-predetermined ones.
public OurObject : Field

public T GetFieldByName<T>(string fieldName) where T : class
        {
            return _fields.ContainsKey(fieldName) ? _fields[fieldName] as T: null;
        }

public Field this[string index]
    {
        get { return _fields.GetFieldByName<Field>(index); }
        set { _fields.SetFieldByName(index, value); }
    }

Ok cool. But then I realized that some of these objects are actually arrays. Damn. ok, so back to the drawing board. But we're having a bit of trouble finding a good way to handle the generic access/management of these Array/Not Arrays.
The ideas we've come up with so far include:

Creating a collection object extending from field and placing it in (FieldCollection), extending any field objects that are arrays from that.
Changing Field in the dictionary to Field[] and perhaps adding a property to field "IsArray" (perhaps in conjunction with the previous point)

Are there any better ways of keeping a hash that keeps single objects or arrays of objects the same way? This will be a library so we want it to be as simple to use as possible for the user.
Comment: Any reason for not using existing JSON deserializers?
Answer: Firstly, check out JSON.Net. It will handle serializing/deserializing primitive types and dictionaries etc for you. It will also handle custom data types.
E.g, from the docs (http://james.newtonking.com/json/help/index.html)
The type you expect
public class Account
{
    public string Email { get; set; }
    public bool Active { get; set; }
    public DateTime CreatedDate { get; set; }
    public IList<string> Roles { get; set; }
}

The data
string json = @"{
'Email': 'email@example.com',
'Active': true,
'CreatedDate': '2013-01-20T00:00:00Z',
'Roles': [
    'User',
    'Admin'
    ]
}";

Deserialize and access the dictionary, as you would expect
Account account = JsonConvert.DeserializeObject<Account>(json);
Console.WriteLine(account.Email);


Install Meta Tags and Meta Tags Quick modules on the same site

Question: Short: Are Meta Tag and Meta Tag Quick incompatible modules?
I am configuring a site that has Meta Tag Quick module but it doesn't allow me to have a meta description tag. It creates an Open Graph description meta tag instead.
Then I want to install Meta Tag module but I am afraid of my site crashing or some error. I know I have to do a backup, and I did.
Answer: Couple of things to mention.
Meta Tags Quick does have a meta description field - check the module settings and enable the field for the content types.
Metatags and Meta Tags Quick can be installed on the same site - I've done this successfully (I do suggest testing on a mirror development site first). Bear in mind the two modules will duplicate some fields so you need to decide which fields you want each module to use.
The data cannot be imported from one module to the other however - maybe running SQL commands, but not from Drupal admin


Local martingale up to a stopping time vs local martingale

Question: Let $M$ be a stochastic process, and let $T$ be a stopping time. We call $M$ a local martingale up to $T$ if there exists a sequence $(T_n)$ of stopping times such that $T = \text{sup} T_n$ and $M^{T_n}$ is a martingale for all $n$. Moreover, a martingale is a local martingale if it is a local martingale up to $\infty$.
Now if $M$ is a continuous local martingale up to $T$, how can I show that $M^T$ is a local martingale? Is continuity necessary for this statement? Thanks for any idea :-)
Comment: https://math.stackexchange.com/questions/2329717/is-a-stopped-local-martingale-a-local-martingale
Comment: @d.k.o the $M$ discussed there is already a local martingale up to time $\infty$
Answer: Let $S_n:=\inf\{t\ge 0:|M_t|\ge n\}$. Since $M$ is continuous $S_n\nearrow\infty$ a.s. It suffices to show that $\{S_n\}$ reduces $M^{T}$, i.e. we nts that $(M_{t\wedge T\wedge S_n})$ is a martingale. Let $X\equiv M^T$. Then for each $k\ge 1$, $X^{S_n\wedge T_k}$ is a bounded martingale and $T_k\nearrow T$ a.s. Therefore, for all $s\le t$,
$$
\mathsf{E}[X_{t\wedge S_n}\mid \mathcal{F}_s]=\lim_{k\to\infty}\mathsf{E}[X_{t\wedge S_n\wedge T_k}\mid \mathcal{F}_s]=\lim_{k\to\infty}X_{s\wedge S_n\wedge T_k}=X_{s\wedge S_n} \quad\text{a.s.}
$$
Comment: for the first equality, the dominant convergence theorem is used. Why is its condition satisfied?
Comment: $\lvert (X^{S_n\wedge T_k})_t\rvert\le n$.
Comment: oh thanks a lot!


Definite integral of sign function

Question: I need to calculte the integral of $F(x)=\text{sign}(x)$ (A partial function)
between $x=-1$ and $x=2$.
Of course we need to seperate the integral between $x>0$   and  $x<0$
but is it a case of improper integral ? or just seperate and calculate?
Answer:
Notice:

When $x<0$:
$$\text{sign}(x)=-1$$
When $x>0$:
$$\text{sign}(x)=1$$
When $x=0$:
$$\lim_{x\to0^+}\text{sign}(x)=1$$
$$\lim_{x\to0^-}\text{sign}(x)=-1$$

\begin{align}
\int_{-1}^{2}\text{F}(x)\space\text{d}x &= \int_{-1}^{2}\text{sign}(x)\space\text{d}x \\
&= \int_{-1}^{0}\text{sign}(x)\space\text{d}x+\int_{0}^{2}\text{sign}(x)\space\text{d}x \\
&= \int_{-1}^{0}-1\space\text{d}x+\int_{0}^{2}1\space\text{d}x \\
&=-\int_{-1}^{0}1\space\text{d}x+\int_{0}^{2}1\space\text{d}x \\
&= -\left[x\right]_{-1}^{0}+\left[x\right]_{0}^{2}\\ &= -\left(0-\left(-1\right)\right)+\left(2-0\right)\\ &=-1+2 \\
&=1
\end{align}
Answer: Except at $x=0$, $(|x|)'=\text{sgn}(x)$. Can you conclude ?
Answer: Once you've separated $\int_{-1}^2 F(x) dx$ it becomes by definition of the sign function (and because the value at exactly $x = 0$ doesn't matter)
$$
\int_{-1}^0 -1dx + \int_0^2 1dx
$$
which is easy to calculate and completely proper.
Integrals are very forgiving with discontinuities like this. You need quite a lot of them before they start causing theoretical problems with regards to properness and whether the integral is even defined. Technicality: As long as the set of discontinuities has measure $0$ (where "measure" is a more structured approach to the naïve notion of length / area / volume and so on), in particular if it's countable, then they do not hinder the Riemann integral from being defined.

Definite integral of sign function


Swift how to know if json key is null or no key?

Question: I have a struct that reflects the data from nesed JSON with nilable variables.
struct JsonReceived: Decodable {
    let data: JsonReceivedData
}

struct JsonReceivedData: Decodable {
    let key1: String?
    let key2: String?
    let key3: String?
    let key4: String?
    let key5: String?
}

then I encode the json by JSONDecoder and send it's data to the function.
let res = try JSONDecoder().decode(JsonReceived.self, from: data)

self.addData(res.data.key1)
self.addData(res.data.key2)
self.addData(res.data.key3)
self.addData(res.data.key4)
self.addData(res.data.key5)

The problem is, sometimes the JSON data was look like this
{
    "data": {
        "key1": "value1",
        "key3": "value3",
        "key5": null,
    }
}

and I don't want to send the data from the function if the key doesn't exist,
As you can see in my JSON sample, there is no key2 and key4 key value pair, so I don't want to send them to the function, the key5 is null but still it have a key, so I want it to send to the function even if it's null.
I want the output will something like this.
if isHaveAkeyFromJSON(res.data.key2) {
    self.addData(res.data.key2)
}

Comment: What do you mean by "don't want to send the data from the function if the key doesn't exist"? Where are you sending the data?
Comment: @PGDev what I mean is I want to do something when the key is existed even if it's value is null
Answer: res doesn't know how it was created.  Key's with values have valued, and those that don't don't.  You need to look at the receive JSON again if you want that information.
let testDictionary = try decoder.decode([String: String?].self, from: data)

then test the dictionary for the key:
if testDictionary.keys.contains(res.key2) {
    self.addData(res.key2)
}

Comment: I'm very sorry, but I think there's something missing in my question, the `JsonReceived` was inside the nested json data, I'll gonna edit the question to be clear
Comment: I finally fix it by the structure of this answer, I just changed the docoder to `try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: AnyObject]`
Answer: If you don't need the structs for other things then you can decode and call your method in once
struct JsonReceived: Codable {
    let data: [String: String?]

    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        data = try container.decode([String: String?].self, forKey: .data)
        data.values.forEach {
            self.addData($0)
        }
    }
}


Limit related problems in differentiation

Question: Suppose $\alpha$ and $\beta$ are two roots of the equation $ax^2+bx+c=0$. Find
$$\lim_{x\to\alpha}\frac{1-\cos(ax^2+bx+c)}{(x-\alpha)^2}$$
Please help me to solve this calculus problem
Comment: Welcome to MSE. It will be more likely that you will get an answer if you show us that you made an effort. This should be added to the question rather than in the comments.
Comment: Welcome to Math SE! Your image is barely readable. Since the question is so short, how about type it in [MathJax](https://math.meta.stackexchange.com/questions/5020)?
Comment: Instead of suggesting an edit from a different account, please use your original account and click on "edit" to add details to your question. As it stands, it is not possible if the suggested edit is by you or by someone else pretending to be you. On a side note, using your original account, you can add comments to your own posts irrespective of reputation.
Comment: What kind of rules can you use?
Answer: HINT
We have
$$\frac{1-\cos(ax^2+bx+c)}{(x-\alpha)^2}=\frac{1-\cos[a(x-\alpha)(x-\beta)]}{a^2(x-\alpha)^2(x-\beta)^2}a^2(x-\beta)^2$$
then refer to standard limit as $t\to 0$
$$\frac{1-\cos t}{t^2}\to \frac12$$
Answer: Recall that $\lim_{t \to 0} \frac{1-\cos t}{t^2} = \frac12$.
We have
$$\frac{1-\cos(ax^2+bx+c)}{(x-\alpha)^2} = \frac{1-\cos[a(x-\alpha)(x-\beta)]}{(x-\alpha)^2} = \frac{1-\cos[a(x-\alpha)(x-\beta)]}{[a(x-\alpha)(x-\beta)]^2}\cdot a^2(x-\beta)^2 \xrightarrow{x\to\alpha} \frac12a^2(\alpha-\beta)^2$$
Comment: @MathOverview Yes. Check that $$ax^2+bx+ c = a\left(x - \frac{-b+\sqrt{b^2-4ac}}{2a}\right)\left(x - \frac{-b-\sqrt{b^2-4ac}}{2a}\right)$$
Answer: Hint. Use the Taylor series of
$$
\cos(a(x-\alpha)(x+\beta))
$$
around $\alpha$. That is
$$
\cos(a(x-\alpha)(x+\beta))= 1-\frac{1}{2}(\alpha-\beta)^2(x-\alpha)^2a^2+o((x-\alpha)^3)
$$


Node loses title on submit

Question: I am creating a custom module that allows for users to create blog posts that will be private and related to a project. So I created a new content_type called "tasker_blog" that just has a title and body. The user goes to view their projects and clicks a link which takes them to 'tasker_project/%/blog' % being the id of the project. I have the form being displayed correctly but when I submit the form I have two problems,
  1) the title is lost on submit
  2) getting this error: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids().
Here is the code I have written (some non-relevant parts taken out).
function tasker_project_menu() {
    $items = array();

    $items['tasker_project/%/blog'] = array(
        'title' => 'Private Blog Post',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('tasker_project_blog_form',1),
        'access arguments' => array('view tasker projects'),
        'type' => MENU_CALLBACK,
    );

    return $items;
}

function tasker_project_blog_form($form, &$form_state) {
    drupal_add_css(drupal_get_path('module', 'tasker_project') . '/tasker_project.css');
    global $user;
    module_load_include('inc', 'node', 'node.pages');
    $node = (object) array(
        'uid' => $user->uid,
        'name' => (isset($user->name) ? $user->name : ''),
        'type' => 'tasker_blog',
        'language' => 'und',
    );
    node_object_prepare($node);

    $form = drupal_get_form('tasker_blog_node_form',$node);
    $form['hidden_project_id'] = array(
        '#type' => 'hidden',
        '#value' => arg(1),
    );

    return $form;
}

If I submit with nothing else added I get the error I mentioned above. If I add this (using Kint to display variables):
function tasker_project_node_validate($node, $form, &$form_state) {
    s($_REQUEST);
    s($form_state['values']);
    die();
}

$_REQUEST array output:
array (9) (
    'title' => string (4) "test"
    'body' => array (1) (
        'und' => array (1) (
             array (2) (
                'format' => string (13) "filtered_html"
                'value' => string (13) "
test

"
            )
        )
    )
    'changed' => string (0) ""
    'form_build_id' => string (48) "form-eKWwyFlBOzi4LsajaAiEZBG7J0uOSI1UDVIhiDomeJE"
    'form_token' => string (43) "N421-IiWecixBJGbxTHGcJAIrd6ZutzAW0LAtVSsrJ4"
    'form_id' => string (24) "tasker_project_blog_form"
    'hidden_project_id' => string (2) "10"
    'additional_settings__active_tab' => string (0) ""
    'op' => string (4) "Save"
)

$form_state['values'] array output:
array (27) (
    'nid' => NULL
    'vid' => NULL
    'uid' => string (1) "5"
    'created' => integer 1347038959
    'type' => string (11) "tasker_blog"
    'language' => string (3) "und"
    'changed' => string (0) ""
    'title' => string (0) ""
    'additional_settings__active_tab' => string (0) ""
    'revision' => bool FALSE
    'log' => string (0) ""
    'name' => string (10) "ndenlinger"
    'date' => string (0) ""
    'status' => integer 0
    'promote' => integer 0
    'sticky' => integer 0
    'submit' => string (4) "Save"
    'preview' => string (7) "Preview"
    'body' => array (1) (
        'und' => array (1) (
             array (3) (
                'summary' => string (0) ""
                'format' => string (13) "filtered_html"
                'value' => string (13) "
test

"
            )
        )
    )
    //...MORE HERE REMOVED SINCE NOT RELEVANT
)

So I'm not sure if the two problems are related or not. Once the node is saved I am going to add a row to a custom table that store the nid and the project_id.
Comment: I suggest you print_r or s() $node after    `node_object_prepare($node);`, and before return $form look at $form['title'] ,check it ,maybe problem be in form title field
Comment: Tried that everything looks correct before submitting. I tried setting my own '#validate' and the form_state variable has the title. It is the hook_node_validate() function that is stripping the title for some reason.
Answer: Found the solution in case anyone else ever has this issue:
    drupal_add_css(drupal_get_path('module', 'tasker_project') . '/tasker_project.css');
    global $user;
    module_load_include('inc', 'node', 'node.pages');
    $node = (object) array(
        'uid' => $user->uid,
        'name' => (isset($user->name) ? $user->name : ''),
        'type' => 'tasker_blog',
        'language' => 'und',
    );
    node_object_prepare($node);
    $form_state['build_info']['args'] = array($node);

    $form = drupal_retrieve_form('tasker_blog_node_form', $form_state);
    drupal_prepare_form('tasker_blog_node_form', $form, $form_state);
    $form['hidden_project_id'] = array(
        '#type' => 'hidden',
        '#value' => arg(1),
    );

I used drupal_retrieve_form and drupal_prepare_form and everything seems to work correctly now. Not sure why drupal_build_form or drupal_get_form don't work correctly.
Answer: Test this
function tasker_project_blog_form($form, &$form_state) {
drupal_add_css(drupal_get_path('module', 'tasker_project') . '/tasker_project.css');
global $user;
module_load_include('inc', 'node', 'node.pages');
$node = new stdClass();
$node = (object) array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => 'tasker_blog',
    'language' => 'und',
);
node_object_prepare($node);

$form = drupal_get_form('tasker_blog_node_form',$node);
$form['hidden_project_id'] = array(
    '#type' => 'hidden',
    '#value' => arg(1),
);

return $form;

}

Node loses title on submit


Backdrop blur not updating

Question: I've tried increase backdrop blur via a Alert dialog slider but It doesn't update.When I printed the value It shows update value.What's causing this.
This is my AlertDialog
<code>_blurdialog(BuildContext context){

showDialog<void>(context:context,builder:(context){
   return AlertDialog(
    title: const Text('Background Blur'),
    content: StatefulBuilder(
    builder:(BuildContext context, StateSetter setState) {
     return Column(
       mainAxisSize:MainAxisSize.min,
       children:[
             Container(

          child: Slider(
                value: _blurvalue,
                min: 0,
                max: 5,
                divisions: 5,
                onChanged: (value) {
                setState(() {
                  _blurvalue = value;
                });
              }
            ),
        ),
       ]);
    }),
    actions: <Widget>[
      FlatButton(
        child: const Text('Done'),
        onPressed: () {

          Navigator.of(context).pop(_blurvalue);
          print(_blurvalue);
        },
      ),
    ]
  );});
}
</code>
Container That I want to make blur
<code>Stack(children: <Widget>[ClipRect(
       child: BackdropFilter(filter: ui.ImageFilter.blur(sigmaX: _blurvalue,
                                       sigmaY: _blurvalue),
                                  child: Container(color: Colors.black.withOpacity(0),
                                       height: 400,
                                       width: 400,),
                                   ),
</code>
Answer: Is there a setState() after showDialog()?
Please try to do like below.
when you call showDialog with await and receive data.
And call setState().
<code>_blurdialog(BuildContext context) async {
   var newBlurValue = await showDialog<void>(context:context,builder:(context){    return
   AlertDialog(
       title: const Text('Background Blur'),
       content: StatefulBuilder(
       builder:(BuildContext context, StateSetter setState) {
        return Column(
          mainAxisSize:MainAxisSize.min,
          children:[
                Container(

             child: Slider(
                   value: _blurvalue,
                   min: 0,
                   max: 5,
                   divisions: 5,
                   onChanged: (value) {
                   setState(() {
                     _blurvalue = value;
                   });
                 }
               ),
           ),
          ]);
       }),
       actions: <Widget>[
         FlatButton(
           child: const Text('Done'),
           onPressed: () {

             Navigator.of(context).pop(_blurvalue);
             print(_blurvalue);
           },
         ),
       ]   );});
   setState(() => _blurvalue = newBlurValue);
}

------------- or ---------------
Future<dynamic> _blurdialog(BuildContext context) async {
   return await showDialog<void>(context:context,builder:(context){    return
   AlertDialog(
       title: const Text('Background Blur'),
       content: StatefulBuilder(
       builder:(BuildContext context, StateSetter setState) {
        return Column(
          mainAxisSize:MainAxisSize.min,
          children:[
                Container(

             child: Slider(
                   value: _blurvalue,
                   min: 0,
                   max: 5,
                   divisions: 5,
                   onChanged: (value) {
                   setState(() {
                     _blurvalue = value;
                   });
                 }
               ),
           ),
          ]);
       }),
       actions: <Widget>[
         FlatButton(
           child: const Text('Done'),
           onPressed: () {

             Navigator.of(context).pop(_blurvalue);
             print(_blurvalue);
           },
         ),
       ]   );});
}

...

var newBlur = await _blurdialog(context);
setState(() => _blurvalue = newBlur);

</code>
Comment: Is this need to place inside of `_blurdialog` function
Comment: @Axen_Rangs I updated code. I hope it works and hope to you .
Comment: Wow~!  My pleasure!

Backdrop blur not updating


Is the "Ask for Review" alert part of StoreKit or is it custom?

Question: Is the alert on the right still part of StoreKit and shown automatically after a user chooses a star rating and pressing submit? or is it a custom alert that needs to be added after    SKStoreReviewController.requestReview()
It's not possible to test in development mode as the submit button is disabled, and not more than 3 times in production.  Is that second alert shown? or is it something that needs to be added in order to allow users to add a written review (not a rating)
Answer: It's a built-in UI. According to the documentation:

When you call this method in your shipping app and a rating/review
request view is displayed, the system handles the entire process for
you.


jQuery function not getting called from C# code behind with RegisterStartupScript

Question: I have a jQuery function:

I am trying to call above function from c# as below.
 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "hideInfo();", true);

On page load I get alert("1") but alert("2") is never triggered.
What wrong am I doing?
Comment: @DKR, please try my modified code below
Comment: you are not calling the function anywhere.... although you don't have access to the function outside the scope..... to make it accessible define it in global context or handle click event using jQuery
Comment: when is the c# code get executed?
Comment: Same way I am able to call javascript function. What additional I have to do.!
Comment: @Tal87 - on one of the button click.
Comment: We need more code to diagnose this issue. What happens when you click it? Do you get an error in your console? What does the HTML look like?
Comment: @DKR :  simply define the function in global context
Comment: @FrankerZ. a db call is made on button click after that a label is displayed  for notification and then this function is supposed to fadeout that label.
Comment: @PranavCBalan This is a child page where I am working with jquery.
Comment: @DKR :  move the function definition to outside the document ready handler
Comment: @PranavCBalan. it is called now. But fadeout effect is not working.. the second line of fuction.
Comment: seems like the script is rendered before the page's client onload event is raised. instead of calling the hideInfo,  try writing its content in the registerstartupscript. https://msdn.microsoft.com/en-us/library/bb359558(v=vs.110).aspx
Comment: @tal87, are you suggesting like this: ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "$("#h3memberInfo").fadeOut("slow");", true);
Comment: @DKR the function is calling before the element is loading..... it's better to handle click event using jQuery
Comment: @PranavCBalan. cant do that, its a dynamic button which makes a db call
Comment: @DKR exactly! see example: https://msdn.microsoft.com/en-us/library/z9h4dk8y(v=vs.110).aspx
Comment: @DKR :  use event delegation
Answer: As your function hideInfo() is wrapped inside the $(document).ready block, its not available in the global scope as you try from the code behind.
You can modify your code as below,

Comment: function is called. but 2nd line of funtion to fadeout label is not working.
Comment: Is this the id `#h3memberInfo` correct? Can you check this in the html `view source`? If it's a ASP.Net control id will be changed in the view source.
Comment: on browser, id is childcontainer_h3memberinfo. how do I access clientID in jquery?
Comment: Yes, change the line to `$('#childcontainer_h3memberinfo')` or give a unique css class name and use jquery selector with the class name to the control like, `$('.uniqueClass')`.
Comment: would this ID change in future?
Comment: It won't change unless you change the parent or parent id `childcontainer`
Comment: @DKR, great :-)


Numbers between real numbers

Question: I wonder if there can be numbers (in some extended theory) for which all reals are either smaller or larger than this number, but no real number is equal to that number?!
Is there some extension of number which allows that? Under what conditions (axiom etc.) there is no such number.
Comment: Since we are trying to get rid of [tag:number] tag, see [meta](http://meta.math.stackexchange.com/questions/1363/tag-merging-and-synonyms/2755#2755), I've retagged the question to [tag:number-systems]. If you have a better idea, feel free to replace it with a more appropriate tag.
Comment: It's OK. I found it hard to find a keyword especially since I'm not an expert :)
Answer: Under the axioms of the real numbers this cannot occur. You must add new elements to the real numbers, note that if $\varepsilon$ is smaller than all $\frac1n$ but still positive then $\frac1\varepsilon$ is larger than any real number.
Such $\varepsilon$ is called infinitesimal and their existence is incompatible with the real numbers per se. There is a branch, however, called non-standard analysis in which these numbers play an important role.
One example to such field is called Hyperreal numbers.
Comment: Thanks. What does it mean "under axioms of real numbers". Do I have to abondon one of the axioms to introduce "numbers inbetween"? Which  axiom would that be? Do hyperreals follow the condition about order I required?
Comment: Another example is called [**Surreal number**](http://en.wikipedia.org/wiki/Surreal_number), which I think is more valuable.
Comment: @Gerenuk: Hyperreal numbers are ordered and form a field. However they do not have the Archemedian property of the real numbers (every number is smaller than a natural number). Andre gave another property which does not hold.
Comment: The axiom that has to be abandoned is what is usually called the *Completeness Axiom*. One standard version of it is that any non-empty set (of reals) which is bounded above has a least upper bound.
Comment: @Frank: If you want proper classes, sure. The. You have to explain what is a class, what are ordinals, etc.
Comment: @FrankScience: Could you explain why the surreals are more valuable?
Comment: Sounds interesting. I looked up ordered field. Is it correct that any ordered field is "a subset" of surreal number, so that they are the most general in my sense? How can I find an overview of the axioms the way you mention it? I only found Dedekind-complete on Wikipedia, but that sounds more complex than what you say?!
Comment: .... or in other words: which axioms do I need to add to an ordered field to get the other numbers (surreal, hyperreal)? It's hard to deduce from Wikipedia.
Answer: You want a "non-archimedean" ordered field.  Examples are hyperreals and surreals.  My favorite one: the transseries (G. A. Edgar, "Transseries for Beginners," http://www.math.ohio-state.edu/~edgar/preprints/trans_begin/).  Also try the Levi-Civita numbers: http://en.wikipedia.org/wiki/Levi-Civita_field .  See here http://en.wikipedia.org/wiki/Infinitesimal for many examples.
Answer: Consider the field $\mathbb{R}(x)$ of all (formal) rational functions in one variable with real coefficients. While this is not an ordered field, it is an orderable field -- it is possible to define an ordering $<$ on rational functions that is consistent with the usual laws of arithmetic.
For any ordering $<$ of $\mathbb{R}(x)$, we can define sets $L = \{ a \in \mathbb{R} \mid a < x\}$ and $R = \{ a \in \mathbb{R} \mid a > x\}$, and we have $\mathbb{R} = L \cup R$ -- under this ordering, every real number is either less than or greater than the polynomial $x$.
It turns out the ordering $<$ is completely determined by $L$ and $R$, and conversely each way to choose $L$ and $R$ corresponds to an ordering of $\mathbb{R}(x)$.
The complete list of orderings are:

The ordering "$+\infty$" - $x$ is larger than every real number
The ordering "$-\infty$" - $x$ is smaller than every real number
The ordering "$a^+$" - $x$ is infinitesimally larger than $a$
The ordering "$a^-$" - $x$ is infinitesimally smaller than $a$

The labels I've chosen for the orderings refer to "where" $x$ is placed in relation to the real line.
Some good buzzwords that relate to this sort of topic are:

Real closed field
Formally real field
Real algebraic geometry
Semi-algebraic geometry

There is an easy way to write down a first-order theory whose models are examples of the sort of number system you ask for. For example,

Start with the language of ordered fields
Add a new constant symbol $\varepsilon$
Add in all of the ordered field axioms
Add in one axiom $0 < \varepsilon$
For every positive integer $n$, add in one axiom $\varepsilon < n$

Every model of this theory will have a number $\varepsilon$ with the property that it is larger than every non-positive real number, and smaller than every positive real number.
Comment: Can I add multiple $\varepsilon$ this way? It won't break any field axioms? Will all the maths from university still work (integrals etc.), or do I need some exceptions (i.e. where does the archimedian matter)? Is which is the field which is more than real numbers, but leaves as much undergrad math valid as possible?
Comment: If you stick to elementary algebra, any real closed field is indistinguishable from the real numbers in terms of what theorems/identities are true or what computations you can do. If you want to do real analysis (e.g. integrals), you need to set things up more along the lines of non-standard analysis. (i.e. hyperreals)

Numbers between real numbers


drupal 6: passing multiple arguments to a view using code

Question: I have a template file that uses execute_display to pass arguments to a view and this works great for single arguments. However, one of my arguments is a taxonomy id and the form allows the user to choose multiple term ids.
I've set the view to accept multiple arguments in the form 1+2+3 etc. But when i pass execute_display an array array containing arguments in the form of term1+term2 it doesn't work.
Any ideas how to pass multiple ids as one argument using code
Comment: Kind of difficult to give you a straight answer based on the info you provided... Can you post some sample code along with what happens when the code is executed? Or maybe even a little more in-depth explanation of what your situation is?
Answer: the array must be array in "execute" then this array in array - in "preview", e.g
<code>$args = array($arg1, $arg2, $arg3);
$view2->execute('block_1', $args);
print  $view2->preview('block_1', array($args));
</code>


argument type mismatch exception while marshelling the java object

Question: I am converting a java object into xml string with the help of jaxb context marshelling technique.When i try and run the program as main class.it converts it into xml string but when i call the method from different class in project.it throws argument mismatch exception.
I am using tomcat 7 and jdk 6 and running the code in eclipse.
Please find marshelling snippet as below.
<code>    JAXBContext context = JAXBContext.newInstance(Test.class);

                 m = context.createMarshaller();

                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

sw = new StringWriter();

                m.marshal(request, sw);
</code>
Please guide on why its failing when i m running it into a project.
Answer: Please follow below way to marshal the Java object and use the XML writer to make xml format.
<code>   JAXBContext context = JAXBContext.newInstance(Test.class);

   Marshaller m = context.createMarshaller();

            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

   NamespaceFilter outFilter = new NamespaceFilter(null, false);
   ByteArrayOutputStream baOPStram = new ByteArrayOutputStream();

   //Use XML writer to create the xml file.
   XMLWriter writer = new XMLWriter(baOPStram);

   outFilter.setContentHandler(writer);

   m.marshal(**YourJavaObject**, outFilter);

   message = new String(baOPStram.toByteArray());
</code>
if you wish to save the xml file to somewhere , please give the reference of the output file.
<code>   OutputStream os = new FileOutputStream("xyz.xml");
   m.marshal(**YourJavaObject**, outFilter);
</code>
also set the below property before
<code>   m.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
</code>


Differential equation with fractional expression

Question: I consider this ODE:
$$ y'+\frac{1}{y}=\tau,\quad \tau>0,y(0)=c\in \mathbb{R}_{\geq 0} $$
For the homogeneous case $$ y'+\frac{1}{y}=0 $$
I get $ y(x)=\sqrt{c^2-2x} $.
For the inhomogeneous case I consider now
$ y(x)=\sqrt{(c(x))^2-2x}\\y'(x)=\frac{c'(x)\cdot c(x)-1}{\sqrt{(c(x))^2-2x}} $
and plugged into the differential equation I get this
$$ y'(x)+\frac{1}{y(x)}=\frac{c'(x)\cdot c(x)}{\sqrt{(c(x))^2-2x}}=\tau $$
From here I don't have any idea how to proceed further.
Comment: There is no "homogeneous case" in a non-linear DE. Not every DE has a symbolic solution, indeed those that do are an extremely thin subset, just add any term in $x$. However, this one is autonomous and thus after isolating $y'$ can be recognized as separable.
Answer: Hint
Make life easier switching variables
$$y'+\frac{1}{y}=\tau \implies \frac 1{x'}+\frac{1}{y}=\tau\implies x'=\frac{y}{\tau  y-1}$$
Comment: Why do you replace $y'$ with the expression $\frac{1}{x'}$?
Comment: @hallo97. To make life much simpler (as I wrote)


Which metric(s) can I use to evaluate how well a group of binary models agree in their predictions?

Question: My request is best explained with an example. Suppose the upcoming week of (American) football matches are
<code>Bills vs Jets
Saints vs Falcons
Rams vs Lions
Packers vs Bears
Chiefs vs Chargers
Giants vs Cowboys
</code>
I ask three guys and three girls "who will win?" Their responses are
guy 1: Bills and Rams
guy 2: Jets, Rams, and Giants
guy 3: Rams, Chiefs and Cowboys
girl 1: Jets, Rams, and Giatns
girl 2: Jets, Rams, and Bears
girl 3: Packers and Chiefs
I'm looking for a metric that can help me answer the following:

How well do the guys agree?
How well do the girls agree?
Which gender has a higher level of agreement?

Notes

I do not know wins each game (nor do I care).
Each person doesn't predict on the exact same set of games

Current Approach
My current idea is to implement the following algorithm.
Let $P_i$ be the set of predictions for model $i$. Given $P_1$, $P_2$, ..., $P_N$,
For $i$ from 0 to N:
Assume $P_i$ is the "source of truth". Now I can calculate $F_i$ as the average F score amongst the other predictors $\{P_k\}_{k \neq i}$. This tells me how well the other predictors agree with $P_i$.
Finally, I just can just average the F scores (perhaps weighted by sample size).
I suspect there's a more elegant approach to this..
Comment: How about the [Phi coefficient](https://en.m.wikipedia.org/wiki/Phi_coefficient)?
Comment: @mhdadk Thanks! Can you elaborate how that would work for my use case? Do you suggest I calculate Phi for every pair of distinct predictors (in the same group) and then average the results?
Answer: For convenience, I'll use a simpler version of your example. Consider the teams $A,B,C,$ and $D$. There are ${4 \choose 2} = 6$ possible matches between these teams:

Match Number ($M$)
Team 1 ($T = 0$)
Team 2 ($T = 1$)

1
$A$
$B$

2
$A$
$C$

3
$A$
$D$

4
$B$
$C$

5
$B$
$D$

6
$C$
$D$

Let $M$ correspond to the match number, such that $M = 1$ corresponds to the match $A$ vs. $B$, for example. Let $G$ denote the gender of the person being asked, such that $G = 0$ corresponds to boy and $G = 1$ corresponds to girl. Also, let $N$ denote the number assigned to the gender, such that $G = 0$ and $N = 3$ corresponds to "boy 3", for example. Finally, let $T$ represent the prediction of the team that wins, such that $T = 0$ corresponds to team 1 and $T = 1$ corresponds to team 2.
As an example, the probability $P(T = 1 \mid M = 4, G = 1, N = 2)$ corresponds to the probability that girl 2 predicted that team $C$ will win in the match $B$ vs. $C$. Note that, regardless of the values of $M,G,$ and $N$, $T$ is a Bernoulli random variable.
The Phi coefficient is just the Pearson's correlation coefficient for two Bernoulli random variables. In other words, it is the normalized covariance of two Bernoulli random variables. In our case, we are interested in the normalized covariances for two triplets of Bernoulli random variables: $(T \mid G = 0,N = 1,T \mid G = 0,N = 2,T \mid G = 0,N = 3)$ and $(T \mid G = 1,N = 1,T \mid G = 1,N = 2,T \mid G = 1,N = 3)$.
As for how to compute these two normalized covariances, you can get started here.


Can I prevent users from modify the parameters in C#

Question: I'm coding in C# for a group of people, I'm designing the signature of the methods to be coded and I need a way to ensure that people won't modify some parameters they will receive.
They receive big structures so they are sent by reference, but I want they to consume the data without modifying the original values. But since the structures are big we don't want to make copies of them.
We can assume they don't want to change the data and we only need to protect them from making mistakes.
What solutions does C# offer?
Here's and example
class MyDataBlok {
    List<double> samples;
    int someParams;
    double lots of other params
    }

class MySetOfDataBlock
{
    List<MyDataBlock> DataSet;
    bool SomeParam;
    Double lots of other params;
}

class MethodsToBeCoded
{
    ProcessSetOfData( /*some tag defining data as protected*/ MySetOfDataBlock data)
    {
         //Here I want code that uses data without modifying data
         // nor the content on any data.DataSet[i]
    }
}

Comment: What?! `struct`-instances are passed by value. Anyway I don´t understand your problem. Can you show some sample-code that shows what you´re trying to do?
Comment: You can´t prevent the person implementing a method to modify the arguments passed *by reference*. However as `struct´s are passed *by value* modifcations within that method don´t have any effect on the calling code.
Comment: @himbrombeere Using a `struct` is fine unless it contains reference type members like `List<...>`, right? In that case adding/removing to/from the list would reflect in the calling code?
Comment: Have a look at [this](http://stackoverflow.com/questions/10981888/const-function-parameter-in-c-sharp) It has already been asked and answered. or [this](http://stackoverflow.com/questions/114149/const-correctness-in-c-sharp)
Comment: You should take a look at unit testing.
Comment: I'm sorry, but your question is not very clear. Are you asking how to make sure your users will not change the values of arguments they send to your methods before they execute your methods?
Comment: if the DataSet is Huge and you definte it as struct then send it by copy .. arent you wasting resources in every iteration ?
Answer: The pessimistic answer is None. If the want to change the data, they will. There is nothing you can do except making copies.

The optimistic answer assumes they don't want to change the data and you only need to protect them from making mistakes. Now that is possible:
Don't give them any setters. You did not say what your data looks like so I can give you only a vague description:
Do not expose the setters. Give them interfaces to your data classes that do not have setters, return collections as IEnumerable<> instead of the modifiable instance they are and so on. Make sure that through the interface they get to your data, your data cannot be modified.
Comment: I added an exemple now, I like the ideas you are exposing, can you concrete a bit ?
Comment: @nvoigt someone can easily cast `IEnumerable<>` back to `List<>` and they can modify. Base class library has solution to all problems if you try to be optimistic !! :)
Comment: @AkashKava This is C#... if you don't make a copy, "evil" people can just use reflection. Non-evil people are fine with `IEnumerable`. Any solution is not security, just being helpful so it's harder for the user to make mistakes. Casting an IEnumerable to List is not a mistake, it's intentional evil and falls into category one in my view.
Comment: @AkashKava And I hate those readonly fakes that .NET uses. They give you an `IList` and then throw exceptions half the time you actually use it as an `IList`. That's violating about any guideline I know about programming. Least surprise, ease-of-use, you name it.
Comment: @nvoigt, `IEnumerable` isn't same as `IList`, as `IList` has `Count` property,  `IList` allows random access and `IEnumerable` allows only sequential access. `IList` is never necessarily modifiable. It isn't fake, it is good guideline on how to access "Sequentially" and "Randomly" I think they are genuine computing standards. Anyway you be happy with `IEnumerable` and try to access objects always sequentially and call random access as some violation, purely your choice.
Comment: @AkashKava I would like an interface that gives read-only random access and Count. I don't like an interface that promises reading *and* writing and then crashes when I actually try. That's bullshit. In this case, it's crystal clear at compile time that it should be read-only. Passing something that poses as read/write but throws at runtime is not my style.
Answer: If you are looking for a const keywork like in C++ to prevent mutability of data then unfortunatly this does not exist.
What you can do is pass immutable classes (classes without data modifying properties or methods). -> Remove the public set; and just use read only methods
Answer: Pass AsReadOnly() as parameters, no one can modify it.
https://msdn.microsoft.com/en-us/library/e78dcd75(v=vs.110).aspx
 public void SomeMethod(IList<SomeData> list){
       ....
 }

Call as...
 SomeMethod( myList.AsReadOnly() );

So you can create class,
Class MySetOfDataBlock
{
    private List<MyDataBlock> _DataSet;
       = new List<MyDataBlock>();

    public IList<MyDataBlock> DataSet{
        get{
           return _DataSet.AsReadOnly();
        }
    }

    bool SomeParam;
    Double lots of other params;
}


nginx 502 hindering eb Worker and SQS causing Visibility Timeout to not be respected

Question: I am having the same symptoms as https://forums.aws.amazon.com/message.jspa?messageID=580990#580990 but on EB Docker Preconfigured Python (i.e. visibility timeout not respected). First off, my queue visibility timeout (configured in both eb and sqs) is 1800s.
I receive a 502 after 60s since my messages take more than 60s to be processed (and after 60s the queue of course attempts to retry the message since it received a 502). I tried the .ebextensions proxy.conf solution (mentioned in the link by ecd_bm) to no avail.
My /var/log/nginx/access.log gives:
127.0.0.1 - - [18/May/2015:08:56:58 +0000] "POST /scrape-emails HTTP/1.1" 502 172 "-" "aws-sqsd/2.0"

My nginx /var/log/nginx/error.log gives:
2015/05/18 08:56:58 [error] 12465#0: *32 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "POST /scrape-emails HTTP/1.1", upstream: "http://172.17.0.4:8080/scrape-emails", host: "localhost"

My /var/log/aws-sqsd/default.log gives:
2015-05-18T08:56:58Z http-err: 8240b585-61c3-4fba-b99a-265ace312308 (1) 502 - 60.050

First off, my /etc/nginx/nginx.conf looks like:
# Elastic Beanstalk Nginx Configuration File

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log    /var/log/nginx/access.log;

    include       /etc/nginx/conf.d/*.conf;
    include       /etc/nginx/sites-enabled/*;
}

I used to receive 504s after 60s but adding the following to /etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker-proxy.conf  (which is included by /etc/nginx/nginx.conf) got rid of them (but they were replaced with 502s):
map $http_upgrade $connection_upgrade {
    default     "upgrade";
    ""          "";
}

server {
    listen 80;

    location / {
        proxy_pass          http://docker;
        proxy_http_version  1.1;

        proxy_set_header    Connection      $connection_upgrade;
        proxy_set_header    Upgrade     $http_upgrade;
        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_buffers 8 16k;
        proxy_buffer_size 32k;
        proxy_connect_timeout 1800s;
        proxy_send_timeout 1800s;
        proxy_read_timeout 1800s;

    }
}

I have literally set every param that defaults to 60s to 1800s -- http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers
I have noticed that uwsgi log says:
your mercy for graceful operations on workers is 60 seconds
Could this be the issue? -- How do I fix this if it is?  If not how do I stop the 502s.
Also, I have added the following to /etc/nginx/uwsgi_params to no avail:
uwsgi_read_timeout 1800s;
uwsgi_send_timeout 1800s;
uwsgi_connect_timeout 1800s;

After editing an nginx config file (using ssh), I would always "Restart App Servers" in the eb web interface and then test.
Any ideas on how to get rid of the 502 and make the visibility timeout respected when processing a message?
Comment: Did you set harakiri in your uwsgi file? Did you try to set limit-post?
Probably client_max_body_size may also help. I had similar issue before and it was really hard to figure out...
Comment: Did you manage to find a solution to this? I have the exact same problem.
Comment: Would also love to see an answer to this. Seems like it should be possible to set nginx based on the environment's visibility timeout with an appropriately-crafted ebextension.
Answer: Here's what I've worked out so far. No idea if this is a "safe" way to access the queue visibility timeout but it seems to do the trick on my ruby worker environment for now:
packages:
  yum:
    jq: []

commands:
  match_nginx_timeout_to_sqs_timeout:
    command: |
      VISIBILITY_TIMEOUT=$(
        /opt/aws/bin/cfn-get-metadata --region `{"Ref": "AWS::Region"}` --stack `{"Ref": "AWS::StackName"}` \
          --resource AWSEBBeanstalkMetadata --key AWS::ElasticBeanstalk::Ext |
          jq -r '.Parameters.AWSEBVisibilityTimeout'
      )
      if [[ -n "${VISIBILITY_TIMEOUT}" ]]; then
        echo "proxy_read_timeout ${VISIBILITY_TIMEOUT}s;" > /etc/nginx/conf.d/worker.conf
        service nginx restart
      fi

I actually had a secondary use for this data so ended up splitting it out into a properties-cache file as well. See https://github.com/Safecast/ingest/pull/43/files for details.
I get the impression updating the visibility timeout from the beanstalk UI won't update this value until the next deployment, but I'm okay with that situation since it doesn't change for an environment very often anyway.


How to Visualize Logistic Regression Prediction Process

Question: I'm trying to do a visualization for a Logistic Regression (LR) model for a binary classification task.
I've built an LR model to predict the gender of English text authors (male / female) using scikit-learn in Python. I saved the model, and extracted the features and the coefficients. Now given a new random text, I would like to show the decision procedure of the model (I know how to do the actual prediction by code). For example had it been a Decision Tree model, then I'd just show the decision tree. My question is, what do I need in order to simulate the decision process of LR? Let's say I have the following text:
i hang out with my wife every weekend
And my features are: hang, my wife, weekend. My model calculates TFIDF values of the features and builds a features table like so:

hang
my wife
weekend

0.01
0.02
0.03

And let's say the model predicts a high probability of the author being a male. Now I would like to show how it came to this decision based on some calculations. For example a (wrong but easy) way would be to say "the male-related features are more than the female-related features (and then point out the features), and thus this was classified as a male text".
So how could I show the calculations process that the model had done to come up with its decision? I'm not necessarily looking for a library to do it automatically, I only need to know the steps and then I can implement something of my own.
I hope I'm clear enough, but otherwise please let me know and I'll try to clarify it better.
Comment: I think you need to read a simple introduction to [logistic regression](https://en.wikipedia.org/wiki/Logistic_regression) and the interpretation of it's coefficients. CV.SE has a number of threads on the matter: This one here: https://stats.stackexchange.com/questions/86351/ is quite good to start with. Logistic regression coefficient have additive effects on the [log odds](https://en.wikipedia.org/wiki/Logit) domain, any "visualisation" needs to start there.
Answer: One advantage of decision tree is that it can be used to explain a single prediction, by following the prediction process which mimics that of a human being.
Logistic regression does not have this property. When you build a logistic regression model, it is a global model that represents all your data and it cannot explain a single prediction as decision tree does.
If you want to stick with logistic regression, but have the possibility to explain a single prediction, you may consider post-hoc explainability technique, e.g. LORE(https://arxiv.org/abs/1805.10820), which builds a tree locally around the sample you want to explain. While post-hoc  technique is normally intended for blackbox models, it can also provide explanation for a single prediction from your logistic regression.
Answer: Seems that you're looking for something in SHAP's fashion, have a look at these examples and keep in mind that explanatory techniques are often non-causal but just associative measures of explanation.
Comment: Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Answer: As @usεr11852 suggested, I read through Logistic Regression on Wikipedia, and found the following formula:
$$P(x)=\frac{1}{1+e^{-(\beta_0 + \sum{\beta_ix_i})}}$$
$P(x) \equiv probability \space of \space positive \space sample$
$\beta_0 \equiv logistic \space regression \space interception$
$\beta_i \equiv coefficient \space i$
$x_i \equiv feature \space value$
I have the coefficients (clf.coef_), the interception (clf.intercept_), and the feature values. So this is easy to implement now.


Is nonempty intersection with every set in a base a sufficient condition to prove the closure of the set is the whole space?

Question: I've noticed in some proofs, if $A\subset B$ for $B$ a topological space, it seems that it is enough to show that $A$ intersects every set in a base of $B$ to prove that the closure $\overline{A}=B$. I noticed this for instance in the proof that the closure of $\mathbb{Q}$ is $\mathbb{R}$ in the lower limit topology.
Is this ultimately true in general, that if a subspace meets every subset of a base of the ambient space, that the closure of the subspace is the whole space? If so, why?
Comment: When a subset has this property it is called *dense*.
Comment: Yes and denseness is a very important topological property in analysis.
Answer: Yes, it's true. Suppose that $\langle X,\mathscr{T}\rangle$ is a space, $\mathscr{B}$ is a base for $\mathscr{T}$, and $D\subseteq X$ is such that $D \cap B \ne \varnothing$ for each $B \in \mathscr{B}$. Let $x \in X$ be arbitrary, and let $V$ be any open nbhd of $x$. By the definition of a base there is some $B\in\mathscr{B}$ such that $x\in B \subseteq V$. By hypothesis $D\cap B \ne \varnothing$, so $D \cap V \supseteq D\cap B \ne \varnothing$. Thus, every open nbhd of $x$ meets $D$, and therefore $x \in \operatorname{cl}D$. Since $x$ was an arbitrary point of $X$, $\operatorname{cl}D = X$.
Comment: Thanks Brian, I appreciate the explanation.
Answer: $\bar{A}$, the closure of $A$, is equal to the intersection of all the closed sets containing $A$. Therefore, $\bar{A}^c$, the complement of $\bar{A}$ in $B$, is equal to the union of all the open sets that don't meet $A$. So showing $\bar{A}=B$ is equivalent to showing $\bar{A}^c=B^c=\varnothing$, i.e. there are no open sets in $B$ that don't meet $A$ (except $\varnothing$ itself, of course). But given a base for the topology of $B$, any open set in $B$ is a union of elements in the base, so to show $\bar{A}^c=\varnothing$, it suffices to show that every element of the base meets $A$. So, your conjecture is true!


define software path

Question: I have an older version already installed.
I have upraded the package using setup.py install command. But the path is not correctly set. When I type "s3cmd" is shows the older version of software.
# s3cmd
s3cmd [options] <command> [arg(s)]              version 1.2.6
  --help    -h        --verbose     -v     --dryrun    -n

# which s3cmd
/usr/local/bin/s3cmd

The correct version is in different folder and I will like that to be used whenever I type the command.
# /usr/bin/s3cmd
Consider using --configure parameter to create one.

How do I set path?
I have added path to .bash_profile file but it does not work.
PATH=$PATH:/usr/bin/s3cmd

Answer: Three problems here and one suggestion.

If you write it like that, it sets a local variable named PATH during the execution. What you want to change is the environment variable. To do so, you need the export command. So you need to write export PATH=/some/stuff:/here:instead:..
Additionally, if your system is finding the wrong command first, then you need to reorganize the precedence of PATH so that it finds the right one first. Being the first item in the PATH list is hit first. So, if you add the declaration at the end, you aren't actually tackling the problem. So, you need to write export PATH=/new/path:$PATH.
PATH takes paths, not files. You should be writing /usr/bin, not /usr/bin/s3cmd.

Lastly, my suggestion to you is not to fix your path, but to remove your old s3cmd since you don't seem to use it anymore.
Comment: Point 2 and 3 worked. The software was not installed using rpm so rpm -e is not working to remove the old version.

define software path