text:
Q: K-Fold Cross validation ambiguity? I am using K-Fold cross validation to test my trained model.But i was amazed that for every K-fold the accuracy is different.For instance if use 5-K fold ,every fold has different accuracy.So which fold should i select?Does averaging of 5 fold results is ultimate choice?.Secondly,why the data-set split ratio(70:30) is different in case of 5 fold and 10 fold cross validation.It should be same.

A: I think that you may be misunderstanding how cross-validation works, as well as what it is used to do. Additional detail on your research question and methodology would help.
But TL;DR: the average of the cross-validation accuracy measures (generally mean squared error or successful classification) approximates the accuracy of your model on test data (a held-out sample or new data set). How well it approximates that depends on your model, and whether or not that's even what you're interested in depends on what you are trying to determine with cross-validation.
For how it works, k-fold CV randomly divides your data into k subsections and then tests the model fit using fold k as a validation set against the remaining k-1 folds. This procedure is repeated k times, and since each repetition uses different folds for the validation/test sets it is unsurprising (and normal) that different results are produced.
As to the data split ratios I don't know enough to comment. Some clarification on what you are referring to by "data-set split ratio(70:30)" would be valuable, as well as the ratios you observed when using 5 vs. 10 folds. Are you using a software package to do the data-splitting and cross-validating, and if so, how are you calling it?


text:
Q: Server-side object in PHP is empty when returned to client I have a server-side PHP script that generates an object containing aggregated data from a database.  The script builds the object, encodes it to JSON and returns it to the client, where the original request was made by this jQuery.ajax call :
$.ajax({
        async: false,
        url: 'scripts/getDataforUser.php?firstName=' + _firstName+ '&lastName=' + _lastName,
        dataType: "json",
        success: function(result) {
          //Do stuff with 'result' object
          //result object sometimes comes back empty
        },
        error:function (xhr, ajaxOptions, thrownError){
             displayError('An error occurred while fetching data');
             return;
          }
      });

My problem is that I occasionally get an empty result object returned, this seems to happen with larger requests, but is seemingly random so it's been a challenge to trace the cause.  I'm using Zend Server with Eclipse as my IDE, I've debugged the script several times to confirm that A) there is data, and B) the result object is getting properly encoded to JSON using json_encode($data, JSON_FORCE_OBJECT) on the PHP side.
Again, this error only seems to occur with larger objects, since I can see data when debugging the getDataforUser.php script directly, I'm focused on the client-side and seeing if there's some error on being received on the Javascript side.
I'm not sure at this point what's getting lost in translation from the server to the client.  Is the issue with how I'm JSON encoding the object in PHP?  How I'm calling the server to get that encoded object?  A combination of both?  Or is there something more fundamental that I'm missing?
UPDATE:
Hi Ben, as stated in my comment, one detail I neglected to include in my original post that may provide some insight into the issue, is that a fellow developer running the same URL on his local dev server gets a null object returned, while I just get an object with empty properties.  Could our local server's PHP configuration be the issue?  In my PHP.ini file, I have the following settings for my resource limits, which I expected would be more than enough in this case.
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 600     ; Maximum execution time of each script, in seconds
max_input_time = 180 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M      ; Maximum amount of memory a script may consume (128MB)

From debugging the script directly, the script doesn't take more than 600 seconds to execute this query.  It parses the request data well within the time limit, and no errors are thrown regarding memory exhaustion.
Update 2:
My development environment is running the Apache web server.
Update 3:
@Ben - I took a quick look at the Apache core documentation and the Timeout directive's default is 300 seconds, although as I mention above, I am using Zend Server CE as my dev server ( it sits on top of Apache), so it may have its own default Timeout directive that it sets in its internal Apache configuration.  Again, I'll have to check.
Also just to clarify, my partner on this software project is having the same issue, only instead of getting back an empty object, he gets back null.
Update 4:
Ok, I was doing some extensive testing and validation on my local web server.  One detail that is relevant is that the database I'm querying is hosted on MS SQL Server, I'm using the SQL Server Native Client PHP Driver as my database abstraction layer.  Anyway, after reviewing the logs I see that the query for data is timing out with the SQL Native Client reporting the following:
[0] => Array
        (
            [0] => 08S01
            [SQLSTATE] => 08S01
            [1] => 258
            [code] => 258
            [2] => [Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258].
            [message] => [Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258].
        )

    [1] => Array
        (
            [0] => 08S01
            [SQLSTATE] => 08S01
            [1] => 258
            [code] => 258
            [2] => [Microsoft][SQL Server Native Client 11.0]Communication link failure
            [message] => [Microsoft][SQL Server Native Client 11.0]Communication link failure
        )

    [2] => Array
        (
            [0] => 08S01
            [SQLSTATE] => 08S01
            [1] => -2147467259
            [code] => -2147467259
            [2] => [Microsoft][SQL Server Native Client 11.0]Communication link failure
            [message] => [Microsoft][SQL Server Native Client 11.0]Communication link failure
        )

This seems to be the primary source of empty data in the result object, I'm still searching for information on this error, I'm not sure if the timeout setting I need to update is in the SQL Server Native Client itself or in the database.  More investigation is needed.
Update 5:
I've ruled out the database timeout, the remote connection timeout setting is set to 600 seconds.  I've read throughout online that using the PDO ODBC driver is preferred as timeouts don't seem to be an issue with it.  I'm going to try that and see if it resolves this timeout issue.
Final Update Resolution:
Ok, so switching to the PDO driver seems to have resolved my timeout issue, I verified the PDO driver working on both our local dev machines and our staging server.  I'm still not sure what would be causing the SQL Server Native Client to time out when using the SQLSRV driver.  For now I'll mark the main issue as resolved since I'm now getting back data.  Thanks Ben D and everyone else for your support.

A: There are three obvious sources of the problem: it's either a problem returning the ajax request, or with the PHP script that is being called, or with webserver serving the php result. I'm guessing it's a PHP problem, but just to be thorough:
It's possible that your $.ajax() request is timing out because even though jquery has no timeout default, different browsers seem to set their own timeouts on ajax requests]1. This may be further complicated by the async: false setting, though I'm not sure. I'm guessing this isn't it, as I think that browser-timeouts would trigger the ajax error clause and you note in comments that someone was able to reproduce directly from the URL, but it's easy to make sure using firebug (or equivalent) and watching the traffic.
The likelihood that it's a PHP problem is much higher. A few things to check: 1. That the PHP script isn't either timing out (max_execution_time in ini file) or hitting a memory cap (memory_limit in ini). Also make sure that you're not accidentally trying to encode non-utf8 characters and you're just happening to hit them in large objects (in which case json_encode() will return null). Try turning on errors, see if any are generated, and also try running json_last_error() to see if there was a problem creating the json string.
Lastly, it's possible that Apache is the problem. Your request looks pretty tiny, so I doubt it's hitting any request url limits, but it's possible that the web server is timing out while waiting for php to create the object... check what your TimeOut value is in your http.conf file.

A: Don't pass the GET parameters through the URL. use the "data" property instead:
$.ajax({.... data: { firstName: "bob", lastName: "smith" } });

redpajama_set_name: RedPajamaStackExchange


text:
Q: pyspark : fetch common data from dataframe when comparing values of given columns I have two pyspark dataframes like this.
data_frame A
+----+---+
|name1| id1|
+----+---+
|   a|  3|
|   b|  5|
|   c|  7|
+----+---+

data_frame B
+----+---+
|name2| id2|
+----+---+
|   a|  13|
|   b|  15|
|   c|  17|
|   d|  6|
|   e|  0|
|   f|  3|
+----+---+

I want to fetch dataframe B contents  if values of name1 (from df a)  and name2 (from df b)  matches.  which is as shown below.
o/p dataframe
+----+---+
|name2| id2|
+----+---+
|   a|  13|
|   b|  15|
|   c|  17|
+----+---+

I want to avoid computationally expensive methods such as collect() etc.
How this can be done in apache spark?

A: from pyspark.sql.functions import *

df1.join(df2, df1.name1 == df2.name2).select('df2.*')

OR (using sql)

df1.registerTempTable("tableA")
df2.registerTempTable("tableB")

val result = sqlContext.sql("select b.name2, b.id2 from tableA a join tableB b on a.name1=b.name2")

result.show()
+----+----+
|name2| id2|
+----+----+
|   a|  13|
|   b|  15|
|   c|  17|
+----+---+


text:
Q: Android vs. Java on PC : Different HttpResponse? I run SAME code on my PC (windows 7 64 bit, Eclipse, Java) and on a Android Virtual Machine and I get different results.
Its a small programm that shoult print me the HttpResponse fully as String.
Results on PC:

HTTP/1.1 405 Method Not Allowed [Allow: GET, HEAD, Date: Thu, 03 Nov 2011 17:57:22 GMT, Content-Type: text/html; charset=UTF-8, Server: gws, Content-Length: 11816, X-XSS-Protection: 1; mode=block, X-Frame-Options: SAMEORIGIN]

Result on Android:
org.apache.http.message.BasicHttpResponse@44ec9da8

The code I ran on PC was:
HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
            "http://www.google.com");

    try {
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.toString());

And on Android:
HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
            "http://www.google.com");

    try {
        HttpResponse response = httpclient.execute(httppost);
        return response.toString();

Im asking becasue I wrote a App that would work on PC - works with the HttpResponse content - but on android it seems that is has NO content at all...
Could anyone please explain me this? Or tell me how to get the response content (headers) as String on android?

A: This is because HttpResponse.toString() is implemented differently on Android and on PC (different jvm and framework components implementations!). To get HttpHeaders correctly I guess you need to use something like:
http://developer.android.com/reference/org/apache/http/HttpMessage.html#getAllHeaders%28%29
Anyhow see javadoc for reference on this.

A: You don't actually run the same code.
Android's BasicHttpResponse currently has no toString() method at all and goes on to invoke java.lang.Object.toString() giving you fully.qualified.class.name@hashcode.
Your desktop version of HttpClient most likely has a toString() similar to this one from HttpClient 4.1.3:
public String toString() {
    return this.statusline + " " + this.headergroup;
}

Using toString() for any non-debugging/logging purposes isn't good practice -- you should extract the right information using actual get methods or just return the HttpResponse itself.


text:
Q: grunt-express not serving all bases I've been using grunt-express to serve files as I develop at home. I recently changed the structure of my application and moved my assets folder outside of my app folder.
The structure looks like this at the moment:
+---project
|
+---app
|   +---bower_components
|   +---mainView
|   +---view2
|   +---components
|   \---css
+---assets
|   +---fonts
|   +---json
|   \---less
+---node_modules
|
\---Gruntfile.js

Previously, the assets folder was located inside of the app folder.
The only change I've made to my Gruntfile.js is adding the assets folder in the bases array, like this:
express: {
            all: {
                options: {
                    port: 9001,
                    hostname: "localhost",
                    bases: ['app', 'assets']
                }
            }
        }

However, only the content within app is being loaded:

Running only express and express-keepalive yields the same result as running it from my main dev task.
My versions:
"grunt": "^0.4.5",
"grunt-express": "^1.4.1"

Have I misinterpreted something about using grunt-express or is it a bug?
Please tell me if you need any more information and thanks in advance.

A: My first guess would be to change 'assets' to '../assets' if you're starting within app folder.
Where is your Gruntfile.js located in that tree? Can you provide a screenshot of the full directory listing? From the top to wherever your Gruntfile is.


text:
Q: Does clojure have raw string? In Python, I can prefix an r to a string literal (raw string) to tell the interpreter not translate special characters in the string:
>>> r"abc\nsdf#$%\^"
r"abc\nsdf#$%\^"

Is there a way to do the same thing in Clojure?

A: Please also note that if you're using Counterclockwise (the Eclipse plugin for Clojure), there is a mode, called "smart paste" (disabled by default) which takes care of correctly escaping special characters when you paste inside an existing literal String.

A: May be of use to a literal regular expression for such purposes.
user=> #"abc\nsdf#$%\^"
#"abc\nsdf#$%\^"
user=> (type #"abc\nsdf#$%\^")
java.util.regex.Pattern
user=> (println (str #"abc\nsdf#$%\^"))
abc\nsdf#$%\^
nil

A: Clojure strings are Java strings and the reader does not add anything significant to their interpretation. The reader page just says "standard Java escape characters are supported."
You can escape the \ though:
user> (print "abc\\nsdf#$%\\^")
abc\nsdf#$%\^

This only affect string literals read by the reader, so if you read strings from a file the reader never sees them:
user> (spit "/tmp/foo" "abc\\nsdf#$%\\^")
nil
user> (slurp "/tmp/foo")
"abc\\nsdf#$%\\^"
user> (print (slurp "/tmp/foo"))
abc\nsdf#$%\^nil
user>

So, I think the basic answer is no.


text:
Q: Comma usage after the start of a sentence beginning with time It has been an ongoing debate in my office among managers that there should be a comma used after a statement of time.
Ex.
At 1135 Hrs., (Subject) Was observed doing something that he shouldn't have.
It is this comma after the abbreviated hours we are having a debate over. Is it proper to put it there or is it not needed in this instance?

A: I would say a comma is required, since one could view "At 11:35" as a dependent clause.
This would be apparent by rephrasing the sentence:

(Subject) was observed doing something that he shouldn't have (at 11:35).

A dependent clause preceding an independent clause must be separated by a comma (see rule 4a, grammarbook.com).


text:
Q: Where do HTTP request cookies originate? I have a VB.NET app that sends a POST request to a script on my server that is running Cloudflare. I always get an error when sending the request from the app, however using a Firefox extension to simulate the request works fine. With the use of Fiddler I think I have found the cause of the problem:
When sending the request with the Firefox addon an extra header is attached to the request:

Cookie: __cfduidxxxxxxxxxxxx

This cookie is from Cloudflare, but where does it come from, ie. how can I get this cookie value and send it with my requests from the VB app? I tried copying and pasting the cookie into the app and it worked fine, so this leads me to conclude that I need this cookie, however this value is unique for each user so I cannot simply hardcode it into the app.
Quick side-note: Not sure if this helps, but if I send a GET request from the VB app it works fine without the __cfduid cookie.

A: Look for a Set-Cookie header coming back from the server on it's response. It will expect to get that value back on subsequent requests in a Cookie: header. This value is usually an opaque string that is classified by a path, although not always.


text:
Q: Generator that yields subpatterns of an original pattern with zeros introduced I have the following problem in which I want to generate patterns with a 0 introduced. The problem is that this should be space efficient, and thus I would like to use a generator that creates and returns one of the patterns at a time (i.e. I do not want to create a list and return it.) I am at a loss here because I don't know what I am doing wrong in calling the generator, so any help would be appreciated!
original pattern = [ 0.  1.  1.  2.]
generator should generate and return these: [ 0.  0.  1.  2.], [0.  1.  0.  2.], [ 0.  1.  1.  0.]
However I can just yield one of the patterns with a call to the generator (the additional 1.0 is not an issue just to not cause any confusion...) and not all of them in succession.
yielded subpattern = (array([ 0.,  1.,  0.,  2.]), 1.0)
The following is my code:
import numpy as np
def removeoneletter(subpattern):
     # generator = []
     originalpattern = subpattern
     subpatterncopy = subpattern.copy()
     nonzero = np.nonzero(subpattern)
     listnonzero = nonzero[0].tolist()
# only replace elements at nonzero positions with zero
     for i in listnonzero:
          subpatterncopy = subpattern.copy()
          position = i
          transaction = subpatterncopy[i]
          np.put(subpatterncopy, position, 0)
          print('subpattern generator')
          print(subpatterncopy)
          # generator.append((subpatterncopy, transaction))
          yield((subpatterncopy, transaction))
          if i == len(listnonzero):
              break

and the function gets called by another function like so:
def someotherfunction():

  combinations = removeoneletter(subpatterncopy)

  for x in combinations:
       # x = next(combinations)
       print('yielded subpattern')
       print(x)

A: Not being an numpy expert, this part looks a bit weird to me:
for i in listnonzero:
    ....
    if i == len(listnonzero):
          break

Your for loop assigns elements of listnonzero to i, and then you test that against the length of the list. If the listnonzero had five elements [5,42,6,77,12] and the first element you pick from the list happens to be number 5, you would break the loop and exit after the first iteration.
Your code would (probably) work in Javascript or similar where "for i in something" assigns an index to i instead of a list member.
If this does not help, try removing yield and adding a print statement there to see if your listnonzero and i are what you expect them to be.
Just a thought.
Hannu


text:
Q: Making a regular angular app, a modular angular app Okay so I am trying to learn how to create a modular angular app, but I don't really know how it would look. Based on my code what would I need to do to make it modular? My app is pretty small but I still want to try and get the idea down as for how to create a modular app so that I can just do that from the beginning the next time I create a web app. I didn't include the css as it seems irrelevant for this question. Help would be greatly apprciated.
index.html
<!DOCTYPE html>

  To do App
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>To do App</title>

  <link rel="stylesheet" type="text/css" href="css/style.css">

You have {{getTotalTodos()}} tasks

      <input class="search-input" type="text" ng-model="searchText" placeholder="enter search term" />

          {{todo.text}}: {{todo.date_created}}

          <button class="clear-btn" ng-click="removeTask(todo)">Remove</button>
          <button class="clear-btn" ng-click="editTask(todo)">Edit</button>

      <form>
        <input class="add-input" placeholder="task name" type="text" ng-model="text" ng-model-instant />
        <button class="add-btn" ng-click="addTask()">
Add
</button>
      </form>

index.js
angular.module('demoApp', [])
    .controller('todoCtrl', TodoCtrl);

function TodoCtrl($scope) {

    $scope.todos = [{
        id: 1,
        text: 'Mow the lawn',
        selected: false
    }, {
        id: 2,
        text: 'Wash the car',
        selected: false
    }];
    $scope.id = $scope.todos.length + 1; //later create an uuid

    $scope.getTotalTodos = function () {
        return $scope.todos.length;
    };

    $scope.addTask = function () {
        $scope.todos.push({
            editMode: false,
            text: $scope.text,
            id: $scope.id,
            date_created: Date.now,
            selected: false
        });
        $scope.text = '';
        $scope.id = '';
    };

    $scope.removeTask = function (todo) {
        /*$scope.todos = _.filter($scope.todos, function (todo) {
            return !todo.selected;
        });*/
        $scope.todos.pop(todo);
        //update server now with ngResource...
    };

    $scope.showDetails = function (task_id) {
        var found = $filter('filter')($scope.todos, {
            id: task_id
        }, true);
        if (found.length) {
            $scope.selected = JSON.stringify(found[0]);
        } else {
            $scope.selected = 'Not found';
        }
    }

    $scope.editTask = function(todo) {
        todo.editMode = true;
        console.log(todo);
    };

    $scope.save = function(todo) {
        todo.editMode = false;
        // update data at server now too. $scope.todos is up-to-date
    }
    $scope.updateTask = function (task_id) {
        // search $scope.todos for the item to update
        var indexOfTask;
        for (var i = 0; i < $scope.todos.length; i++) {
            if ($scope.todos[i].id === $scope.id) indexOfTask = i;
            $scope.todos[i] = todo;
            $scope.todos.push();
            $scope.text = '';
            $scope.id = '';
        }

        // update the todo

    };

}

A: Essentially just make a new file for every angular whatever (factory, controller, directive, etc.)
I use this syntax
angular.module('myapp.functionName.type', [])
   .type('functionName',);

Then in your app.js, in your case index.js
angular.module('myapp', ['myapp.functionName.type', ... ]) ;


text:
Q: test if hostname exists from command line without ping we have a script that needs to take action on a finite list of hosts.  but every time we add or remove a host to the /etc/hosts file, we end up having to update this script.
basically, say my hosts file looks like:
192.168.100.1     hostip_1
192.168.100.2     hostip_2
192.168.100.10    hostip_3
192.168.100.20    hostip_5

and my script (bash) does something like:
callmyfunction hostip_1
callmyfunction hostip_2
callmyfunction hostip_3
callmyfunction hostip_5

if i want to add hostip_4 to the list of hosts, i now have to go in and edit my script and add it to the list.  while it's a small edit, it is still a step that can be forgotten in the process (especially if someone new to the system comes in).
is there a way i can test to see if 'hostip_1' is a valid hostname within the system (without pinging the host or grepping the /etc/hosts file)?  we may use multiple hosts files, and different configurations may have different filenames, so i can't rely on trying to grep a single file.  i need the system to do that work for me.
any clues?

A: first, my statement about things not being in the hosts file is wrong.  that is exactly where they are.  dumb on my part.
but the answer is:
getent hosts

that will get it to print everything out, and i can do a lookup from there.

A: As you are populating the /etc/hosts file, I am assuming that you are not using DNS. So below solution wont fit your use case. But it will still get you some pointers.
In a working DNS environment, you can check the host name to its corresponding IP with below command
# host host_name

This is will give the IP address of the host. In case the host name does not exists, then it will give you corresponding host not found message.
You can parse the output of above command and can deduce whether a give host name exists.

A: might not be in your /etc/hosts file... better search for the name and see if an ip can be found:
(($(dig +noall +answer google.de |wc -c)>0)) && echo exists

this is bash, can be adaptet to pretty much everything.
dig +noall +answer google.de

returns the ips if found. If empty, that name cannot be used in the computer running this code.

A: If all the targets are on the same subnet (same network), use arping, it will check that hosts are available using ARP.


text:
Q: How to share my app page in my facebook? I can post my text to the facebook account through my app (facebook integration - using facebook sdk).
But I want to post/share my whole app page to my facebook account, that means, I have paint design in my app, so I want to share my designed image into facebook.
Here i paste the screenshots of my doubts, kindly check,
but actual process which i have, when i click the facebook icon, the Post to Wall page is opened and I can type the text only liked in the second image, after clicking the Share button in the above page, i get the output things in my facebook account as shown as,

but i want to share the whole page along with image to my facebook account, Now I hope you understand my question.give me the solution. Thanks


text:
Q: How to approximate a function to make it differentiable?
I was reading a paper which made the median function
$$ \mathcal{M} = \arg\min_c\sum_{j=1}^N\|x_j-c\|_p,$$
differentiable by replacing arg min with a softmax to form
a weighted average, i.e. $ \mathcal{M} \approx \mathbf{s}^T\mathbf{X},$
where the softmax function is
$$ s_i = \frac{e^{-\frac{1}{T}||x_j-x_i||}}{\sum_{q=1}^ne^{-\frac{1}{T}||x_j-x_q||}}$$

Softmax was used so that the weights are between $0$ and $1$, we could easily put it through other functions too. But, are there any other different methods to approximate this function (and similar ones) to make them differentiable?

A: There are a near infinite number of ways to approximate it. In the context of optimization, one common technique would be to optimize the parameters at a sequence of fixed temperature parameters $T$ (using your softmax formulation), gradually increasing $T\rightarrow\infty$. In other words, optimize first at $T=10$ then $T=100$, etc. all the while using the latest optimization weights $x_i$ from the previous optimization.
This has the effect of making the softmax converge to the maximum value, while also optimizing over a differentiable function.


text:
Q: Zend Framework - Router Rewrite with Regex I have been trying to shortern this route:
http://abc.localhost/user/view/index/id/1
to this:
http://abc.localhost/user/1
with the following portion of code in my bootstrap but I keep getting an error stating that the 'Reversed route is not specified', any ideas why?
$route = new Zend_Controller_Router_Route_Regex(
    'user/(\d+)',
    array(
        'module'        => 'user',
        'controller'    => 'view',
        'action'        => 'index'
    ),
    array(
        1 => 'id'
    )
);
$router->addRoute('user', $route);

Thanks,
Martin

A: If you want to use the URL helper with Regex routes you need to pass a 4th parameter to Zend_Controller_Router_Route_Regex that it can use to rebuild the route. This 4th parameter should be a string in a sprintf-format which it can inject the params into.
In your case it would be something like:
$route = new Zend_Controller_Router_Route_Regex(
    'user/(\d+)',
    array(
        'module'        => 'user',
        'controller'    => 'view',
        'action'        => 'index'
    ),
    array(
        1 => 'id'
    ),
    'user/%d'
);
$router->addRoute('user', $route);

There is some info on this right at the end of the manual section on Regex routes: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.regex - but it's easy to miss.


text:
Q: Using vnet_subnet_id to bring up the AKS cluster through terraform - Azure I am trying to create an AKS cluster using terraform.I'm using the vnet_subnet_id parameter in the default_node_pool block - so the Kubernetes nodes come up in the subnet id that i pass here.
However, i would want to also conditionally be able to create the kubernetes cluster in the normal way, that is, without using the vnet_subnet_id parameter(As this is parameter is only optional).This way it just brings up the Kubernetes nodes in the Vnet/subnet that are part of the `node resource group(usual way)
 default_node_pool {
        name = "${var.name}"
        vm_size = "${var.aks_node_type}"
        vnet_subnet_id = "${var.subnetid}"
     }

Is it possible to execute a condition and implement both the scenarios.

A: sure, use something like this:
vnet_subnet_id = var.condition == "something" ? var.subnetid : null

and then based on this condition it will either put it into your subnetid or create a new one


text:
Q: Error when adding a simple little image to a button in Tkinter I'm trying to learn to use python TTK, i keep getting an error when adding a simple little image to a button, can be any image in the same file as the program. This is the code :
# from PIL import ImageTk, Image
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image

window = Tk()

window.wm_iconbitmap('icon.ico')
window.geometry('200x200')
user = ttk.Label(window, text='Username').pack()
userEnt = ttk.Entry(window).pack()
passW = ttk.Label(window, text='Password').pack()
passEnt = ttk.Entry(window).pack()
logButton = ttk.Button(window, text='Login').pack()

myImg = PhotoImage(file='C:\\Users\edwin\Desktop\Python\Tkinter\logo.png')

logButton.config(image=myImg, compound=RIGHT)

window.mainloop()

This is the error I am receiving and I don't know why!

File "C:/Users/edwin/Desktop/Python/Tkinter/trial.py", line 18,
  in
      logButton.config(image=myImg, compound=RIGHT)
  AttributeError: 'NoneType' object has no attribute 'config'

A: you are assigning values to the output of pack(), rather than to the output of the class instantiation.  You need another line:
 # from PIL import ImageTk, Image
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image

window = Tk()

window.wm_iconbitmap('icon.ico')
window.geometry('200x200')
user = ttk.Label(window, text='Username')
user.pack()
userEnt = ttk.Entry(window)
userEnt.pack()
# so on and so forth


text:
Q: WeibullGen Parameters using umontreal.iro.lecuyer.randvar package java I am trying to generate weibull random numbers using WeibullGen from umontreal.iro.lecuyer.randvar package this is my code
RandomStream stream = new MRG32k3a();
for(int i=0;i<5;i++) {
   int result = WeibullGen.nextDouble(stream, alp, lam,bet);
   System.out.println(result);
}

But I am a little confused about the parameters I mean does lam means the scale or the rate parameters, I think alp means the shape parameter. finally, I am confused about the last parameter bet what it present. I tried to look online but it wasn't clear to me.
Thanks in advance


text:
Q: Mule Flow Reference Component throwing TransformerMessagingException while passing json I have two flow one receive the xml payload and another json. I am routing the xml call to json flow using mule flow reference component after converting the xml to json payload. and second flow returns the json payload that i need to convert back to xml and reply to client.
My mule flow reference is throwing TransformerMsgException while receiving the json response from second flow.
Failed to transform from "json" to "java.lang.String" (org.mule.api.transformer.TransformerException). Message payload is of type: String

Here are the code for your reference -
 <flow name="post:/chkdb:application/json:chkd-config">
         <logger message="========json payload==>>>>====  #[message.payload]" level="INFO" doc:name="Logger"/>
         <set-variable variableName="GGG_Number" value="#[json:ggg]" doc:name="Variable"/>
                 <!--  db call returns the payload-->
         <choice doc:name="Choice">
             <when expression="#[message.payload.size()>0]">
                 <set-payload value="{"indicator":"True"}" mimeType="application/json" doc:name="Set Payload"/>
             </when>
             <otherwise>
                 <set-payload value="{"indicator":"False"}" mimeType="application/json" doc:name="Set Payload"/>
             </otherwise>
         </choice>
         <logger message="=========after producing json output=======" level="INFO" doc:name="Logger"/>
     </flow>
     <flow name="post:/chkdb:application/xml:chkdb-config">
         <logger message="========= xml payload========  #[message.payload]" level="INFO" doc:name="Logger"/>
         <json:xml-to-json-transformer mimeType="application/json" doc:name="XML to JSON"/>
         <flow-ref name="post:/chkdb:application/json:chkdb-config" doc:name="post:/chkdb:application/json:chkdbapi-config"/>  <!-- Getting exception here -->
         <logger message=" after subflow call ==== #[message.payload]" level="INFO" doc:name="Logger"/>
         <json:json-to-xml-transformer mimeType="application/xml" doc:name="JSON to XML"/>
         <logger message="after json to xml conversion" level="INFO" doc:name="Logger"/>
     </flow>

XML Request -
<ggg>DeJmp03bkqALlRFYmgu4+A==</ggg>

How i should retrieve the json response from other flow to current flow.

A: There is something missing here

*

*First flow name: post:/chkdb:application/json:chkdbapi-config

*Second flow name: post:/chkdb:application/xml:chkdbapi-config

*Flow ref in second flow: post:/chkdb:application/json:chkdb-config
You are not referencing First flow.

A: So from your flow posted I can find few issues as follows :-
1. You are using  where is the flow post:/chkdb:application/json:chkdb-config doesn't exits and it should be post:/chkdb:application/json:chkdbapi-config instead
2. Right now in the flow you are using <when expression="#[message.payload.size()>0]"> where as the message payload is in String format right now.
So, you can either use <when expression="#[message.payload.length()>0]">, using length() instead of size() or put a <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>before choice if you use #[message.payload.size()>0]
So the full code will be something as follows :-
 <flow name="post:/chkdb:application/json:chkdbapi-config">
          <logger message="========json payload==>>>>====  #[message.payload]" level="INFO" doc:name="Logger"/>
       <!--   <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/> --> <!-- incase you use #[message.payload.size()>0] in your choice -->
                  <!--  db call returns the payload-->
    <set-variable variableName="GGG_Number" value="#[json:ggg]" doc:name="Variable"/>
          <choice doc:name="Choice">
              <when expression="#[message.payload.length()>0]">
                  <set-payload value="{"indicator":"True"}" mimeType="application/json" doc:name="Set Payload"/>
              </when>
              <otherwise>
                  <set-payload value="{"indicator":"False"}" mimeType="application/json" doc:name="Set Payload"/>
              </otherwise>
          </choice>
          <logger message="=========after producing json output=======" level="INFO" doc:name="Logger"/>
      </flow>

      <flow name="post:/chkdb:application/xml:chkdbapi-config">
          <logger message="========= xml payload========  #[message.payload]" level="INFO" doc:name="Logger"/>
          <json:xml-to-json-transformer mimeType="application/json" doc:name="XML to JSON"/>
          <flow-ref name="post:/chkdb:application/json:chkdbapi-config" doc:name="post:/chkdb:application/json:chkdbapi-config"/>  <!-- Getting exception here -->
          <logger message=" after subflow call ==== #[message.payload]" level="INFO" doc:name="Logger"/>
          <json:json-to-xml-transformer mimeType="application/xml" doc:name="JSON to XML"/>
          <logger message="after json to xml conversion" level="INFO" doc:name="Logger"/>
      </flow>


text:
Q: Django Many2Many constraint I am using Django with Django-Rest-Framework (no forms, no django_admin). I have the following models
class Company(models.Model):
    ...

class Sector(models.Model):
    ...
    company_id = models.ForeignKey(Company)
    employees = models.ManyToManyField(Employee)

class Employee(models.Model):
    ...
    company_id = models.ForeignKey(Company)

Employee can be in multiple Sectors and a Sector can have multiple Employees. (ManyToMany).
I want to add a constraint employee.company_id == sector.company_id in order to add a record into the Many2Many table.
I can do this validation in the serializers from the DRF, but I also want to handle this on the model level.
I added a through table in the ManyToManyField
class Sector(models.Model):
    ...
    company_id = models.ForeignKey(Company)
    employees = models.ManyToManyField(Employee, through='M2MTable')

class M2MTable:
    ...

    def save():
        # employee.company_id and sector.company_id validation is done here

This will handle saving an M2MTable object, but however this will not handle related object references Sector.employees.add(Employee)
From here I found out I can achieve this with m2m signals.
Is there another way of handling this


text:
Q: implementing Brute Force in c++ I have a problem that deals with optimization of a game that includes 2 players.
So we have an undirected connected graph with a number of edges and some vertices.
Each player has to remove edges and if a vertex is isolated his score increases by
one and then you have to remove another edge. The graph is represented in a so-called
"adjacency matrix".For each one in the array there is a connection between two vertices  For example, in case we have a triangle, we have the following array:
0 1 1 first row
1 0 1 second row
1 1 0 third row
the rows correspond with the vertices and the columns correspond with its possible connections to other vertices. We are assigned to use a recursive function to apply
Brute Force. I have put a lot of thought into writing the code for this function. I
implemented some code and compiled and ran it. I have absolutely no idea why it doesn't
function. My code for this function:
   class Matrix {
        public:
    int berekenZet (bool** array, bool player);
    int berekenScore (bool** array, int rij, int kolom);
    bool checkRij (bool** array, int rij);
    void setGetal (int nummer) {getal = nummer;};
    Matrix ();

private:
    int getal;

    int maxScoreA;
    int huidigScore;
    int maxverschil;
    int maxScoreB;
    int tellerHuidig;

Matrix::Matrix() {
  huidigScore = 0;
maxScoreA = 0;
maxScoreB = 0;

}
 bool Matrix::checkRij (bool** array, int rij) {

            for (int i=0; i<getal; i++) {
    if (array[rij][i] == true)
        return false;
  }
  return true;

}
    int Matrix::berekenScore (bool** Array, int rij, int kolom) {
if (checkRij (Array, rij) == true )
    huidigScore ++;
if (checkRij (Array, kolom) == true)
    huidigScore ++;
return huidigScore;

}
  int Matrix::berekenZet (bool** array, bool player) {
  int score = 0;
  int bestescore = -5;
  int slechtstescore = 5;
  int something;
  something = 0;

  for(int i = 0; i < getal; i++){
  for(int j = i + 1; j <getal; j++){
  huidigScore = 0;

  if(array[i][j]){
    something++;
    array[i][j] = false;
    array[j][i] = false;
    score = 0;
    if(player == true){
      score = score + berekenScore(array, i ,j );
      }
    else{
      score = score - berekenScore(array, i, j);
      }
      cout << "player" << player << endl;
      cout << "score" << score << endl;

    if(huidigScore == 0)
      score = score + berekenZet(array, !player);
    else
      score = score + berekenZet(array, player);

    if(player == true && score > bestescore)
      bestescore = score;
    else if(player == false && score < slechtstescore)
      slechtstescore = score;

      array[i][j] == true;
      array[j][i] == true;

  } //if
}//for
}//for

if(player == true && something != 0){
cout << "bestescore" << bestescore << endl;
return bestescore;
}//  if outside of double for loop
else if(player == false && something != 0){
cout << "slechtstescore" << slechtstescore << endl;
return slechtstescore;
} // else if outside of double for loop

else if(something = 0){
cout << "bestescore" << bestescore << endl;
return 0;

}  // determine whether array was empty when function was called

bestescore and slechtstescore are dutch for best and worstscore.
berekenScore adjusts the number of points earned after an edge
is removed and saves it in huidigScore. So basically 0, 1 or 2.
I call this function in the int main:
cout << "Aantal takken: " << takken << endl;

a = matrix.berekenZet(Array, player);

I ran it using the following adjacency matrix:
5
0 1 1 1 1
1 0 1 0 0
1 1 0 0 0
1 0 0 0 0
1 0 0 0 0
It outputs "score" just 5 times, so it seems to be ignoring the for loops in the function,
also bestescore is once set to some million value and is then set to 5. I'm not a
very experienced programmer so I might just be missing over something..??

A: In your example, you only have 5 edges and thus score is output just five times. The nested loop

for(int i = 0; i < getal; i++)
    for(int j = i + 1; j < getal; j++)

iterates over all the possible edges and the conditions if(array[i][j]) filters out the true edges so the loop will only execute |E| times.
Also, in the loop you set

array[i][j] = false;
array[j][i] = false;

and then

array[i][j] == true;
array[j][i] == true;

and thus only one edge is removed at a time. You probably want one more loop that removes multiple edges at the time to get the brute force implementation.
Edit: You don't seem to be resetting huidigScore at every call. I would recommend to change your helper functions as follows:

int Matrix::berekenScore (bool** Array, int rij, int kolom)
{
int huidigScore = 0;
if (checkRij (Array, rij) == true )
  huidigScore ++;
if (checkRij (Array, kolom) == true)
  huidigScore ++;
return huidigScore;
}

The above function has huidigScore as private variable. Now, instead of the following code snippet:

if(player == true){
  score = score + berekenScore(array, i ,j );
  }
else{
  score = score - berekenScore(array, i, j);
  }
  cout << "player" << player << endl;
  cout << "score" << score << endl;

you can have

int huidigScore = berekenScore(array, i ,j )
if(player == true){
  score = score + huidigScore;
  }
else{
  score = score - huidigScore;
  }
  cout << "player" << player << endl;
  cout << "score" << score << endl;

General advice: Avoid using public variables if you can. They complicate reasoning and debugging of programs.


text:
Q: How to populate data from Data Relationship in Salesforce Marketing Cloud I have created 2 DE(DE1 and DE2). DE1 is Sendable De and DE2 is not sendable.
In DE1 we have field Email(Primary Key), Fname, Lname, City
In DE2 we have field City(Primary Key), PIN
I have created Data relationship between DE1(Email field) and DE2(City field).
Now how to combined both DE by the Data Relationship?
I want to create another DE by Data Relationship which will combined both DE field in below sequence-
Email, Fname, Lname, City, Pin

A: This isn't the purpose of data relationships. You use data relationships to filter data in one data extension based on fields in the second data extension. So in your case you would be joining DE1 to DE2 using the City field as the joining field between both. Then if you knew you wanted all the people from DE1 where the PIN was 1234, you could do this filtering from DE1 using the data relationship.
To merge the data in two data extensions you would use a query in Automation Studio. Your query would look something like:
SELECT DE1.[Email], DE1.[Fname], DE1.[Lname], DE1.[City], DE2.[Pin]
FROM DE1 INNER JOIN DE2 ON DE1.[City] = DE2.[City]

Note you need to make the data extension that will hold this data manually before you run the query and use that data extension as the target of the query.


text:
Q: Change the frame rate of an MP4 video with ffmpeg I have a video in mp4 format with a frame rate of .33 (1 frame for 3 seconds). I want to increase the frame rate to 5 frames/sec. I have tried the below command but it does not do any thing:
ffmpeg -i <input.mp4> -r 5 <output.mp4>

Any idea why ffmpeg is ignoring -r option?

A: I could only get the changed framerate to take effect if the input file was classed as a "raw" file:
ffmpeg -r 5 -f h264 -i input.h264 -vcodec copy -an output.mkv

Without specifying -f h264 it would default to 25 fps and it could not be changed.  Apparently this was because the stream lacked any framerate information at all and this is ffmpeg's default framerate.
Apparently when you use -r as an output option it duplicates or drops frames so the video plays at the same speed - in this case, not what you want!  But changing the input framerate as above will cause the video to speed up or slow down, with no frames lost or duplicated.

A: Such a feature - of changing framerate - is called "conforming" and is often used to produce slow-motion or fast-forward like showing a plant's growth in minutes insted of days. ffmpeg do not allow overwriting/changing framerate without re-encoding. If it does so, duration will change and audio would be out of sync unless separately mended. But I'm afraid audio is not of interest in your case with framerate of .33
You want conforming because you just want to change framerate, but ffmpeg ignores -r silently if framerate is specified in the input file. Since your input file is in .mp4 format, its own framerate take precedence of -r when re-encode isn't needed. For this you need a different tool: mencoder.
Assuming your input file contains no sound - likely true for any video with .33 framerate - what you need is:
$ mencoder -fps 5 -o <output> -ovc copy -nosound <input.mp4>

Notice that mencoder by default produce output in AVI format.

A: I know this is an old question but none of the current answers are the recommended way anymore.
Lossless (video) remuxing
As noted in the comments there is a way to do this where the video does not
have to be re-encoded. It requires remuxing the file to a different containter format MKV and then remuxing it back into an MP4. Here is an example that changes a video to 12 frames/second:
mkvmerge --default-duration 0:12fps --fix-bitstream-timing-information 0 original-video.mp4 -o temp-video.mkv
ffmpeg -i temp-video.mkv -c:v copy slow-video.mp4

If the video contains audio you can also slow that down without changing the pitch, but it is not a lossless conversion. The example below assumes the source video was 24 frames/second so that audio needed to be slowed to half (0.5) speed using ffmpeg's atempo filter.
mkvmerge --default-duration 0:12fps --fix-bitstream-timing-information 0 original-video.mp4 -o temp-video.mkv
ffmpeg -i temp-video.mkv -c:v copy -c:a aac -filter:a "atempo=0.5" slow-video-with-audio.mp4

FFMPEG Wiki Guidance
This is the guidance from the ffmpeg wiki. Note that all of these options do require re-encoding the video.
Speeding up/slowing down video
You can change the speed of a video stream using the setpts video filter. Note that in the following examples, the audio stream is not changed, so it should ideally be disabled with -an.
To double the speed of the video, you can use:
ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv

The filter works by changing the presentation timestamp (PTS) of each video frame. For example, if there are two succesive frames shown at timestamps 1 and 2, and you want to speed up the video, those timestamps need to become 0.5 and 1, respectively. Thus, we have to multiply them by 0.5.
Note that this method will drop frames to achieve the desired speed. You can avoid dropped frames by specifying a higher output frame rate than the input. For example, to go from an input of 4 FPS to one that is sped up to 4x that (16 FPS):
ffmpeg -i input.mkv -r 16 -filter:v "setpts=0.25*PTS" output.mkv

To slow down your video, you have to use a multiplier greater than 1:
ffmpeg -i input.mkv -filter:v "setpts=2.0*PTS" output.mkv

Smooth
You can smooth out slow/fast video with the minterpolate video filter. This is also known as "motion interpolation" or "optical flow".
ffmpeg -i input.mkv -filter "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120'" output.mkv

Other options include slowmoVideo and Butterflow.
Speeding up/slowing down audio
You can speed up or slow down audio with the atempo audio filter. To double the speed of audio:
ffmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv

The atempo filter is limited to using values between 0.5 and 2.0 (so it can slow it down to no less than half the original speed, and speed up to no more than double the input). If you need to, you can get around this limitation by stringing multiple atempo filters together. The following with quadruple the audio speed:
ffmpeg -i input.mkv -filter:a "atempo=2.0,atempo=2.0" -vn output.mkv

Using a complex filtergraph, you can speed up video and audio at the same time:
ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mkv

A: If the input file doesn't have a valid frame rate you might have to set it explicitly
ffmpeg -r 1 -i input.mp4 -r 24 output.mp4

A: The quickest way is to create a BAT-file in the directory with the following rows:
@ECHO OFF

for %%f in (*.mp4) do (

echo "fullname: %%f"

del temp.mkv

mkvmerge --default-duration 0:18fps --fix-bitstream-timing-information 0 %%f -o temp.mkv

del %%f

ffmpeg -i temp.mkv -c:v copy %%f

del temp.mkv

)

You need to have mkvmerge and ffmpeg in the same directory. It changes every mp4-file in seconds automatically with no loss of quality.

A: There is an incredibly simple way -- by using MKVToolNix.
The mp4 file is losslessly converted (in a fraction of a second) to an MKV container with the same codec, internally.


text:
Q: Is there a Python equivalent to Raku's dd (i.e. "tiny data dumper")? I would like to debug my Python code by inspecting multiple variables, dumping out their names and contents, equivalent to Raku's dd (Raku was formerly known as "Perl 6"):
The closest I've found has been mentioned in another post, which compares Python's pprint to Perl 5's Data::Dumper. However, unlike dd, neither of those outputs the name of the variable. dd in Raku is closest to the show function from the Perl 5 module Data::Show, except show additionally outputs the filename and line number.
Here is a demo of Raku's dd in action:
#!/bin/env perl6

my %a = ( :A(1), :B(2) );
my %c = ( :C(3), :D(4) );

dd %a;
dd %c;

Which, when run, results in the following :

Hash %a = {:A(1), :B(2)}
Hash %c = {:C(3), :D(4)}

(By the way, a Hash in Perl or Raku is equivalent to a dictionary in Python)
And here is the closest I have yet been able to get in Python, but it redundantly requires both the name of the variable and the variable itself:
#!/usr/bin/env python

def tiny_dd(name,x):
    print(name + ' is "' + str(x) + '"')

a = { 'A':1, 'B':2}
c = { 'C':3, 'D':4}

tiny_dd('a',a)
tiny_dd('c',c)

Which, when run, results in the following:

a is "{'A': 1, 'B': 2}"
c is "{'C': 3, 'D': 4}"

A: Repeating a name twice when printing a value often grates people who think of variables as having unique values. In Python, however, it is often very hard to find names which reference a particular value, which makes writing a printer like the one you're looking for pretty hard, since you'd need do some very expensive looking around the name space.
That said, PySnooper has done all this heavy lifting for you and can print out a great deal of information on how a program is running, which can be very useful for debugging.
Note that in Python 3.8 you get pretty much what you're looking for with the new = syntax for f strings, which works like this (copied from the release notes):
>>> user = 'eric_idle'
>>> member_since = date(1975, 7, 31)
>>> f'{user=} {member_since=}'
"user='eric_idle' member_since=datetime.date(1975, 7, 31)"

A:
I would like to debug my Python code by inspecting multiple variables

Then you are probably better off using the built-in debugger, pdb.
If you must fall back on debug traces (my not-so-secret vice - just please make sure you don't check them in to version control) then hard-coding the variable name in a print call is not so bad - after all, maybe you can write something more descriptive than the variable name, anyway. There is also the pprint(prettyprint) module to get nicer formatting of complex nested data structures.
But if you really want to be able to find a variable given a string with its name, the built-in locals() and globals() functions provide dicts in which you can look up local and global variables respectively. You can also find global variables (attributes) of other modules (as well as attributes of anything else that has attributes) by name using the getattr() builtin function.


text:
Q: Keras LSTM for Text Generation keeps repeating a line or a sequence I roughly followed this tutorial:
https://machinelearningmastery.com/text-generation-lstm-recurrent-neural-networks-python-keras/
A notable difference is that I use 2 LSTM layers with dropout. My data set is different (music data-set in abc notation). I do get some songs generated, but after a certain number of steps (may range from 30 steps to a couple hundred) in the generation process, the LSTM keeps generating the exact same sequence over and over again. For example, it once got stuck with generating URLs for songs:
F: http://www.youtube.com/watch?v=JPtqU6pipQI
and so on ...
It also once got stuck with generating the same two songs (the two songs are a sequence of about 300 characters). In the beginning it generated 3-4 good pieces but afterwards, it kept regenerating the two songs almost indefinitely.
I am wondering, does anyone have some insight into what could be happening ?
I want to clarify that any sequence generated whether repeating or non-repeating seems to be new (model is not memorising). The validation loss and training loss decrease as expected.
Andrej Karpathy is able to generate a document of thousands of characters and I couldn't find this pattern of getting stuck indefinitely.
http://karpathy.github.io/2015/05/21/rnn-effectiveness/

A: Instead of taking the argmax on the prediction output, try introducing some randomness with something like this:
np.argmax(prediction_output)[0])

to
np.random.choice(len(prediction_output), p=prediction_output)

I've been struggling on this repeating sequences issue for a while until I discovered this Colab notebook where I figured out why their model was able to generate some really good samples: https://colab.research.google.com/github/tensorflow/tpu/blob/master/tools/colab/shakespeare_with_tpu_and_keras.ipynb#scrollTo=tU7M-EGGxR3E
After I changed this single line, my model went from generating a few words over and over to something actually interesting!

A: To use and train a text generation model follow these steps:

*

*Drawing from the model a probability distribution over the next character given the text available so far ( This would be our predictions scores )

*Reweighting the distribution to a certain "temperature" (See the code below)

*Sampling the next character at random according to the reweighted distribution (See the code below)

*Adding the new character at the end of the available text

See the sample function:
def sample(preds, temperature=1.0):
    preds = np.asarray(preds).astype('float64')
    preds = np.log(preds) / temperature
    exp_preds = np.exp(preds)
    preds = exp_preds / np.sum(exp_preds)
    probas = np.random.multinomial(1, preds, 1)
    return np.argmax(probas)

You should use the sample function during training as follows:
for epoch in range(1, 60):
    print('epoch', epoch)
    # Fit the model for 1 epoch on the available training data
    model.fit(x, y,
              batch_size=128,
              epochs=1)

    # Select a text seed at random
    start_index = random.randint(0, len(text) - maxlen - 1)
    generated_text = text[start_index: start_index + maxlen]
    print('--- Generating with seed: "' + generated_text + '"')

    for temperature in [0.2, 0.5, 1.0, 1.2]:
        print('------ temperature:', temperature)
        sys.stdout.write(generated_text)

        # We generate 400 characters
        for i in range(400):
            sampled = np.zeros((1, maxlen, len(chars)))
            for t, char in enumerate(generated_text):
                sampled[0, t, char_indices[char]] = 1.

            preds = model.predict(sampled, verbose=0)[0]
            next_index = sample(preds, temperature)
            next_char = chars[next_index]

            generated_text += next_char
            generated_text = generated_text[1:]

            sys.stdout.write(next_char)
            sys.stdout.flush()
        print()

A low temperature results in extremely repetitive and predictable text, but where local structure is highly realistic: in particular, all words (a word being a local pattern of characters) are real English words. With higher temperatures, the generated text becomes more interesting, surprising, even creative.
See this notebook


text:
Q: How to copy recursively all files not older than 1 day? How to copy recursively all files not older than 1 day?
I first tried
find . -amin -1440 | xargs cp /dest

But it doesn't work because the items given to xargs should be positionned before the /dest argument.

A: You can use the -t option of GNU cp:
   -t, --target-directory=DIRECTORY
          copy all SOURCE arguments into DIRECTORY

You should also use find's -print0 and xargs -0 otherwise, this will fail on file names with spaces or other weird characters:
find . -amin -1440 -print0 | xargs -O cp -t /dest

A better approach might be to use find itself and avoid xargs altogether:
find . -amin -1440 -exec cp -t /dest {} +

Finally, since you mentioned "files", you might want to skip directories, symlinks and other strange beasts and tell find to only look for regular files:
find . -type f -amin -1440 -exec cp -t /dest {} +


text:
Q: Vector Class Problems I have a class of objects called Vector. I am going to include the class early on as I think it is necessary, if not, please tell me so i can delete it immediately (to avoid DV).
class Vec:
    """
    A vector has two fields:
    D - the domain (a set)
    f - a dictionary mapping (some) domain elements to field elements
        elements of D not appearing in f are implicitly mapped to zero
    """
    def __init__(self, labels, function):
        self.D = labels
        self.f = function

    __getitem__ = getitem
    __setitem__ = setitem
    __neg__ = neg
    __rmul__ = scalar_mul #if left arg of * is primitive, assume it's a scalar

    def __mul__(self,other):
        #If other is a vector, returns the dot product of self and other
        if isinstance(other, Vec):
            return dot(self,other)
        else:
            return NotImplemented  #  Will cause other.__rmul__(self) to be invoked

    def __truediv__(self,other):  # Scalar division
        return (1/other)*self

    __add__ = add

    def __radd__(self, other):
        "Hack to allow sum(...) to work with vectors"
        if other == 0:
            return self

    def __sub__(a,b):
        "Returns a vector which is the difference of a and b."
        return a+(-b)

    __eq__ = equal

    def is_almost_zero(self):
        s = 0
        for x in self.f.values():
            if isinstance(x, int) or isinstance(x, float):
                s += x*x
            elif isinstance(x, complex):
                s += x*x.conjugate()
            else: return False
        return s < 1e-20

    def __str__(v):
        "pretty-printing"
        D_list = sorted(v.D, key=repr)
        numdec = 3
        wd = dict([(k,(1+max(len(str(k)), len('{0:.{1}G}'.format(v[k], numdec))))) if isinstance(v[k], int) or isinstance(v[k], float) else (k,(1+max(len(str(k)), len(str(v[k]))))) for k in D_list])
        s1 = ''.join(['{0:>{1}}'.format(str(k),wd[k]) for k in D_list])
        s2 = ''.join(['{0:>{1}.{2}G}'.format(v[k],wd[k],numdec) if isinstance(v[k], int) or isinstance(v[k], float) else '{0:>{1}}'.format(v[k], wd[k]) for k in D_list])
        return "\n" + s1 + "\n" + '-'*sum(wd.values()) +"\n" + s2

    def __hash__(self):
        "Here we pretend Vecs are immutable so we can form sets of them"
        h = hash(frozenset(self.D))
        for k,v in sorted(self.f.items(), key = lambda x:repr(x[0])):
            if v != 0:
                h = hash((h, hash(v)))
        return h

    def __repr__(self):
        return "Vec(" + str(self.D) + "," + str(self.f) + ")"

    def copy(self):
        "Don't make a new copy of the domain D"
        return Vec(self.D, self.f.copy())

I now have to write procedures so that, it works?.
I have completed this assignment, i had 8/9. This is great but i need 9/9 because its being used in another assignment. (This is to clarify that i'm not mindlessly posting homework questions on here.)
def getitem(v,k):
    kthelement = 0
    try:
        kthelement = v.f[k]
    except Exception:
        kthelement = 0
    return kthelement

def setitem(v,k,val):
    v.f[k] = val

def equal(u,v):
    result = False
    unmatched_item = set(v.f.items()) ^ set(u.f.items())
    if len(unmatched_item) == 0:
        result = True
    return result

The first 2 are fine and work. This third one is the problem.
It works sometimes, then some some comparisons it returns False when True or the converse.
Also if,
D = {'a','b','c'}
v1 = Vec(D, {'a': 1})
v2 = Vec(D, {'a':1, 'b':0}

Then v1 == v2
Could someone help me out on this last one please.

A: The problem you are having is that, as far as I can tell, you never implemented the mechanism by which 0 is returned for items in the domain. There are probably many ways to fix this, one way is to construct the dictionary in the constructor:
def __init__(self, labels, function):
    self.D = labels
    self.f = {label: function.get(label, 0) for label in D}

I haven't fully thought through all the implications on the other parts of your function though, but if you intend f to store a dict containing only the parts of the dict function which are in D, then this implements that.
That said, if you intend for f to be something the user can manipulate directly, you may want to implement it as a property (see this question), in which case your original __init__ would work, and you'd move the dictionary comprehension from my version of __init__ into the f property setter.
Also, I should add that I'm assuming from the comment that you want to exclude anything in function that is not in D, so you'll notice that using your original code:
D = {'a','b','c'}
v1 = Vec(D, {'a': 1})
v2 = Vec(D, {'a':1, 'b':0})

print(v1 == v2)

v3 = Vec(D, {'a': 1, 'e': 4})
print(v1 == v3)

Returns:
False
False

But with the dict comprehension, it returns:
True
True

If you would prefer to throw an error if labels not in the domain are found (or allow them in the .f property), you'll have to handle that situation as well.

A: I have solved it. This returns the desired result.
def equal(u,v):
    counter = 0
    for k in u.D:
        if v[k] == u[k]:
            counter += 1
    return counter == len(u.D)


text:
Q: Class org.apache-spark.SparkException, java.lang.NoClassDefFoundError: Could not initialize class XXX Class org.apache-spark.SparkException, java.lang.NoClassDefFoundError: Could not initialize class XXX(class where field validation exists) Exception when I am trying to do field validations on Spark Dataframe. Here is my code
And all  classes and object used are serialized. Fails on AWS EMR spark job (works fine in local Machine.)
val newSchema = df.schema.add("errorList", ArrayType(new StructType()
.add("fieldName" , StringType)
.add("value" , StringType)
.add("message" , StringType)))

    //Validators is a Sequence of validations on columns in a Row.
    // Validator method signature
    // def checkForErrors(row: Row): (fieldName, value, message) ={
    // logic to validate the field in a row }

    val validateRow: Row => Row = (row: Row)=>{
    val errorList = validators.map(validator => validator.checkForErrors(row)
    Row.merge(row, Row(errorList))
    }

    val validateDf = df.map(validateRow)(RowEncoder.apply(newSchema))

Versions : Spark 2.4.7 and Scala 2.11.8
Any ideas on why this might happen or if someone had the same issue.

A: I faced a very similar problem with EMR release 6.8.0 - in particular, the spark.jars configuration was not respected for me on EMR (I pointed it at a location of a JAR in S3), even though it seems to be normally accepted Spark parameter.
For me, the solution was to follow this guide ("How do I resolve the "java.lang.ClassNotFoundException" in Spark on Amazon EMR?"):
https://aws.amazon.com/premiumsupport/knowledge-center/emr-spark-classnotfoundexception/
In CDK (where our EMR cluster definitino is), I set up an EMR step to be executed immediately after cluster creation the rewrite the spark.driver.extraClassPath and spark.executor.extraClassPath to also contain the location of my additional JAR (in my case, the JAR physically comes in a Docker image, but you could also set up a boostrap action to copy it on the cluster from S3), as per their code in the article under "For Amazon EMR release version 6.0.0 and later,". The reason you have to do this "rewriting" is because EMR already populates these spark.*.extraClassPath with a bunch of its own JAR location, e.g. for JARs that contain the S3 drivers, so you effectively have to append your own JAR location, rather than just straight up setting the spark.*.extraClassPath to your location. If you do the latter (I tried it), then you will lose lot of the EMR functionality such as being able to read from S3.
#!/bin/bash
#
# This is an example of script_b.sh for changing /etc/spark/conf/spark-defaults.conf
#
while [ ! -f /etc/spark/conf/spark-defaults.conf ]
do
  sleep 1
done
#
# Now the file is available, do your work here
#
sudo sed -i '/spark.*.extraClassPath/s/$/:\/home\/hadoop\/extrajars\/\*/' /etc/spark/conf/spark-defaults.conf
exit 0


text:
Q: Appium An unknown server-side error occurred while processing the command i download the sample code on Appium website.
i have xcode 6.4 appium 1.4.13.
The i run the simple_test.rb, the code like this. iOS scimitar start ,and put values in textfields. but when click the first button.
error messages come out ,even if i sleep some time, the message is still.

info: [debug] [INST] 2015-11-04 09:54:53 +0000 Debug: Got new command
  7 from instruments: au.getElement('2').rect()
info: [debug] Socket data received (83 bytes) info: [debug] Socket
  data being routed. info: [debug] Got result from instruments:
  {"status":0,"value":{"origin":{"x":94,"y":122},"size":{"width":113,"height":37}}}
info: [debug] [INST] 2015-11-04 09:54:53 +0000 Debug: evaluating
  au.getElement('2').rect()
         2015-11-04 09:54:53 +0000 Debug: evaluation finished 2015-11-04 09:54:53 +0000 Debug: responding with: 2015-11-04 09:54:53 +0000
  Debug: Running system command #8:
  /Applications/Appium.app/Contents/Resources/node/bin/node
  /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js
  /tmp/instruments_sock
  2,{"status":0,"value":{"origin":{"x":94,"y":122},"size":{"width":113,"height":37}}}...
  info: [debug] Responding to client with error:
  {"status":13,"value":{"message":"An unknown server-side error occurred
  while processing the command. (Original error: connect
  ECONNREFUSED)","code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","origValue":"connect
  ECONNREFUSED"},"sessionId":"e7e398a0-e68d-4b71-8a74-1eef7fd6e948"}
  info: <-- POST
  /wd/hub/session/e7e398a0-e68d-4b71-8a74-1eef7fd6e948/element/2/click
  500 138.558 ms - 293

......
Start the driver
Appium::Driver.new(desired_caps).start_driver
module Calculator
  module IOS
    # Add all the Appium library methods to Test to make
    # calling them look nicer.
    Appium.promote_singleton_appium_methods Calculator
# Add two numbers
values       = [rand(10), rand(10)]
expected_sum = values.reduce(&:+)

# Find every textfield.
elements     = textfields

elements.each_with_index do |element, index|
  element.type values[index]
end

# wait { text 'Computer Sum' }
sleep(30)
button(1).click

A: *

*install ios-webkit-debug-proxy by command:
brew install ios-webkit-debug-proxy

*Run ios-webkit-debug-proxy on terminal.

*ios-webkit-debug-proxy requires the "web inspector" to be turned on to allow a connection to be established with iOS Device. To Turn it on Go to settings > safari > advanced > web inspector - On. Try now.


text:
Q: Downloading Java JDK through Script I have been using the following to download JDK 8u112 via a script.
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz

Recently, it throws ERROR 404: Not found and when you go to the link, it shows the same text in Downloading Java JDK on Linux via wget is shown license page instead
I've also tried http://download.oracle.com/otn/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz but it throws 401 Authorization Error.
Is there a new work around on this?

A: It seems like the most recent version of jdk can be downloaded by wget but not the files in the archives.
As such, I'm using casper.js script to login to Oracle and to download.
Following is my script to download Japanese version of jdk8u121. The current script will only attempt to download but will fail on redirect. I'm using download.sh bash script to scan the log to get the url with session parameter and using wget to do the actual download.
You'll need to replace <username> and <password> with valid ones to login to Oracle site.
Change values of jdkTag and jdkFileLink to get the jdk version you want to download.
oraclejdk.js
var casper = require('casper').create({
  verbose: true,
  logLevel: 'info',  // debug
  pageSettings: {
    userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
    loadImages: false,
    loadPlugins: false
  }
});

// login info
var loginUrl='http://www.oracle.com/webapps/redirect/signon?nexturl=https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html';
var username='<username>';
var password='<password>';

// accept license page info
var jdkUrl='http://www.oracle.com/technetwork/';
var jdkTag='jdk-8u121-oth-JPR';

// download jdk info
var jdkFileLink='jdk-8u121-oth-JPRXXXjdk-8u121-linux-x64.tar.gz';

// open login page
casper.start(loginUrl);

casper.thenEvaluate(function(username, password) {
//  this.capture('loginPage.png', {top:0, left:0, width:600, height:800});
    document.querySelector("#sso_username").value = username;
    document.querySelector("#ssopassword").value = password;
    doLogin(document.LoginForm);
}, {
     username: username,
     password: password
});

// login to oracle site
casper.then(function() {
  this.waitForUrl(jdkUrl, function() {
//    this.capture('jdkPage.png', {top:0, left:0, width:1200, height:800});
    this.evaluate(function(jdkTag) {
      disableDownloadAnchors(document, false, jdkTag);
      hideAgreementDiv(document, jdkTag);
      writeSessionCookie('oraclelicense', 'accept-securebackup-cookie');
    }, {
        jdkTag: jdkTag
    });
  }, null, null, 5000);
});

// accept license
casper.then(function() {
  this.waitFor(function checkLink() {
    return this.evaluate(function(jdkTag) {
      return (document.getElementById('agreementDiv' + jdkTag).getAttribute('style') === 'visibility: hidden;');
    }, {
        jdkTag: jdkTag
    });
  }, function then() {
//    this.capture('acceptedLicense.png', {top:0, left:0, width:1200, height:800});
    downlink = this.evaluate(function(jdkFileLink) {
      var jdkElement = document.getElementById(jdkFileLink);
      if (jdkElement) {
        var jdkLink = jdkElement.getAttribute("href");
        jdkElement.click();
        return jdkLink;
      }
    }, {
      jdkFileLink: jdkFileLink
    });
  }, null, 5000);
});

casper.run();

download.sh
#!/bin/bash

url=$(casperjs --web-security=no oraclejdk.js |grep "http://download.oracle.com/otn/java/jdk" $() | sed -e 's/^.*: //')
jdk=$(echo "${url}" | sed -e 's/^.*jdk-/jdk/' |sed -e 's/?.*//')
wget -O "${jdk}" "${url}"

A: This is not a direct answer to your question...but Here is how i get URL to latest jdk download URL
#!/bin/bash

jdkwebinstallerDownloadPage="https://www.oracle.com"$(curl -s https://www.oracle.com/technetwork/java/javase/downloads/index.html | unix2dos | grep "<a name=\"JDK8\"" | sed 's/^.*\.*//g' | sed s/\"//g)
## Above yields https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

jdkinstallerDownloadURL=$(curl -s $jdkwebinstallerDownloadPage | grep windows | grep downloads | grep x64 | grep jdk | grep -v demos | sed -r 's/^.*https/https/g' | sed -r 's/\".*//g')
## yields https://download.oracle.com/otn/java/jdk/8u221-b11/230deb18db3e4014bb8e3e8324f81b43/jdk-8u221-windows-x64.exe

I am now looking to how to download from this url using wget...given that i have cedentials to login into oracle's login webpage which is https://login.oracle.com/mysso/signon.jsp


text:
Q: Remove all manually installed libraries What is the easiest way to remove all development library packages that have been installed manually, i.e. via apt-get install libsomelib-dev, on Ubuntu 22.04?
Something like:
sudo apt-get remove lib*-dev

But excluding those libraries that are needed for other programs. The above command causes a lot of applications and essential system packages to be removed as well - that's what I'm trying to avoid.


text:
Q: how to install and configure a mail server debian I was trying to install on Debian postfix or some mail client to have mails,(its ok if i install a client and it install by itself all the things needed, like postfis and stuffs) Ive read a lot and many tutorials seems to be pretty long, complicated and the worste of all at the end of the configuration just doesnt work anything at my mail, i am novice in this, please, could anybody help me to find a solution a tutorial or give me an explination of how to install it??
Thanks in advance

A: The question would most likely yield better results on SuperUser instead, however I just did the same thing, only in Fedora. Here is the walkthrough I used:
http://www.techotopia.com/index.php/Configuring_a_Fedora_Linux_Email_Server
I'm sure you can use it and simply replace 'yum' with 'apt-get'. Good Luck.


text:
Q: Find all pairs of integers (x,y) such that $x(x+1)(x^2+x+2)=2y^2$ A former Olympiad exercise is to find all pairs of integers $(x,y)$ such that
$$x(x+1)(x^2+x+2)=2y^2.$$
I could not solve this equation. How can one find all solutions?
I tried to rewrite the above equation in a different form, but it did not help. For example, the equation is equivalent to
\begin{align*} x(x+1)(x(x+1)+2)=2y^2&\iff (x(x+1))^2 + 2x(x+1) +1 =2y^2 +1\\
&\iff (x(x+1)+1)^2 =2y^2 +1\end{align*}
Can you tell me how to attack this problem?
Best wishes

A: Set $z=x^2+x$, then we want $z(z+2) = 2y^2$. So $z$ is even and with $w=z/2 \in\Bbb{Z}$, we get the new Diophantine equation
$$2w(w+1) =y^2.$$
Notice that since $x^2+x=z$ has no real solution for $z<\frac{1}{4}$, we can assume $w\ge0$.

*

*If $2|w$, then since $gcd(2w, w+1)=1$ we have that $w+1$ is a square. Then $2w=z$ is a square, and so is $4z$. But since $x = -\frac{1}{2} \pm\sqrt{z+\frac{1}{4}}$ is an integer, $4z+1$ is a square. So $z=w=0$ which means $y=0$, and the two solutions for $x$ are $0$ and $-1$.

*If $2$ does not divide $w$, then $gcd(w, 2(w+1))=1$ implies that $w$ is a square, and this implies that $w+1 = 2k^2$ for $k\in \Bbb{Z}$. So $$x^2 +x = 2w = 4k^2-2$$
and since $x = -\frac{1}{2} \pm\sqrt{4k^2-2+\frac{1}{4}} \in \Bbb{Z}$, we have that $16k^2-7$ is a square. So is $16k^2$, and the only integer squares with difference $7$ are $16$ and $9$, so $k=1$, so $w=1$, so $y= \pm2$ and the possibilities for $x$ are $1$ and $-2$.

A: Since $gcd(x^2+x,x^2+x+2)=2$ we have $x^2+x=2a^2$ and $x^2 +x+2=b^2$ or $x^2+x = a^2$ and $x^2+x+2=2b^2$ where $a,b$ are relatively prime.
1st case: for $x>-2$ we have $$ x^2 <x^2+x+2<(x+1)^2$$ which is impossible. If $x<-1$ then we have $$(x+1)^2 <x^2+x+2<x^2$$ which is again impossible.
2nd case: for $x>0$ we have
$$x^2<x^2+x<(x+1)^2$$ which is impossible.
So we are left with the case if $x<-1$ we have $$(x+1)^2<x^2+x<x^2$$ impossible. So $x=0$ or $x=-1$...


text:
Q: Is this usage of hyphens correct? "Outside, he saw the VonBraun-wheel-designed space station orbiting the Earth."
(As a side note, I do not study the English language, I'm merely an amateur writer)
A "VonBraun wheel" is an idea, and thus a noun, except, it is also two nouns combined together to create a new noun with a different meaning. I'm trying to say that something is noun-verbed, denoting that connection with a hyphen (as taught in HS). Examples being black-colored, water-washed, etc.
I'm arguing with myself whether it should be as it is, or:
"... VonBraun wheel-designed ..."
or
"... VonBraun wheel designed ..."
or
"... VonBraun-wheel designed ..."

A: I don't think any of your examples make sense; they're not phrases that one hears or reads very often. "XXX-colored" and "XXX-designed" are not the same thing, but it's difficult to explain why. (But first, we'll set aside the fact that "XXX-colored" is unnecessary—a "red-colored car" is just a "red car.")

*

*In "red-colored," "red" is an adjective and "colored" a participle, so this is an adjective-participle compound modifier (or maybe an adjective-adjective compound modifier). So a "red-colored car" is a car that is red.

*In "water-washed," "water" is a noun and "washed" is a participle, so this is (you guessed it) a noun-participle compound modifier. A "water-washed deck" is a deck washed with water.

*"VonBraun-wheel-designed space station," however, means "a space station designed by VonBraun wheel" or possibly "a space station wheel-designed by VonBraun" (neither of which makes sense). "Designed" is not necessary. You could just call it a "VonBraun-wheel space station." If you must have "designed," you could say "a space station designed like a VonBraun wheel" or "a space station designed in the form of a VonBraun wheel."

In any case, you can read more about compound modifiers here:
http://www.quickanddirtytips.com/education/grammar/stacked-modifiers
or here:
https://en.wikipedia.org/wiki/Compound_modifier


text:
Q: How to identify the repository url without Git installation? How to identify the Github url to the downloaded repository without having the Git installed on the system?

A: It depends on how you have downloaded the repository.
If you have used the "Download zip" file from a GitHub repository, you can get the sources without having Git installed, but you don't have the full history, and you don't have the .git/config with the remote URL in it.
So with just a copy of the sources, you cannot say for sure from which remote repository hosting site said sources are coming from.


text:
Q: How does Automatic Seeding work - Always On Availability Group I found only these two statements from BOL regarding this Initial Data Synchronization method:
Link 1

Automatic seeding uses the log stream transport to stream the backup
using VDI to the secondary replica for each database of the
availability group using the configured endpoints.

Link 2

During automatic seeding, SQL Server performs a backup over the
network for initialization.

Looking into SQL Server Error logs of both primary and secondary replicas, these two logs caught my attention:
On primary replica

On secondary replica

My question is related to the working nature of automatic seeding, namely where does taken backup is stored before restoring on the secondary replica?

A: As you noted, the docs refer to "log stream transport" when performing automatic seeding. Similar to the way that you can stream movies to your device without downloading a specific file, automatic seeding streams data to the secondary without storing an actual backup file.
While the technical implementation details aren't exactly this, it's essentially taking a backup, but rather than sending it to a storage device or file share, it sends it to the secondary server. Rather than writing a file, it immediately begins to restore to the secondary server. The pseudo-backup is buffered and restored in a single step, without a literal backup being written to file.


text:
Q: What is classified by $H^1(\mathbb{R},SO(p,q))$ and by $H^1(\mathbb{R},SU(p,q))$?
*

*We denote by $F^{\mathbb{R}}_{p,q}$ the quadratic form over the field ${\mathbb{R}}$
$$
F^{\mathbb{R}}_{p,q}(x)=x_1^2+\dots+x_p^2-(x_{p+1}^2+\dots+x_{p+q}^2)
$$
on the vector space $V^{\mathbb{R}}:={\mathbb{R}}^n$ (where $n=p+q$).
By definition,
$$
{\bf O}(p,q)={\rm Aut}({\mathbb{R}}^n,F^{\mathbb{R}}_{p,q}).
$$
By Serre, Local Fields, Section X.2, Corollary 1 of Proposition 4, page 153 in the English version, there is a canonical bijection between
$H^1({\mathbb{R}},{\bf O}(p,q))$ and the set of isomorphism classes of nondegenerate quadratic forms of $n$ variables over ${\mathbb{R}}$,
i.e. isomorphism classes of pairs $(V,F)$ over ${\mathbb{R}}$
where $V$ is an $n$-dimensional vector space and $F$ is a nondegenerate quadratic form on $V$.

*Similarly,
we denote by $F^{\mathbb{C}}_{p,q}$ the Hermitian ${\mathbb{C}}/{\mathbb{R}}$ form
$$
F^{\mathbb{C}}_{p,q}(x)=x_1 \bar x_1+\dots+x_p\bar x_p-(x_{p+1}\bar x_{p+1}+\dots+x_{p+q}\bar x_{p+q})
$$
on the vector space $V^{\mathbb{C}}:={\mathbb{C}}^n$ (where $n=p+q$).
By definition,
$$
{\bf U}(p,q)={\rm Aut}({\mathbb{C}}^n,F^{\mathbb{C}}_{p,q}).
$$
Then there is a canonical bijection between
$H^1({\mathbb{R}},{\bf U}(p,q))$ and the set of isomorphism classes of nondegenerate Hermitian ${\mathbb{C}}/{\mathbb{R}}$ forms of $n$ variables,
i.e. isomorphism classes of pairs $(V,F)$ over ${\mathbb{C}}$
where $V$ is an $n$-dimensional vector space and $F$ is a nondegenerate Hermitian form on $V$.

*Similarly we denote by $F^{\mathbb{H}}_{p,q}$ the Hermitian ${\mathbb{H}}/{\mathbb{R}}$ form  on the vector space $V^{\mathbb{H}}:={\mathbb{H}}^n$ given by the same formula
(where $n=p+q$ and by ${\mathbb{H}}$ we denote the skew field of Hamilton's quaternions with the canonical involution).
By definition,
$$
{\bf Sp}(p,q)={\rm Aut}({\mathbb{H}}^n,F^{\mathbb{H}}_{p,q}).
$$
Then there is a canonical bijection between
$H^1({\mathbb{R}},{\bf Sp}(p,q))$ and the set of isomorphism classes of nondegenerate Hermitian ${\mathbb{H}}/{\mathbb{R}}$ forms of $n$ variables.

Question 1.
  What is classified by $H^1({\mathbb{R}},{\bf SO}(p,q))$?
Question 2.
  What is classified by $H^1({\mathbb{R}},{\bf SU}(p,q))$?

I need explicit functorial descriptions as above rather than formulas for the cardinalities of the corresponding sets.
My feeling is that in both questions $H^1$ classifies nondegenerate forms of n variables with the same determinant as $F_{p,q}$
(modulo squares in Question 1 and modulo norms in Question 2).


text:
Q: Вывод дерева mysql Есть таблица elements следующей структуры Adjacency List Model:
id parent index

Где index - это порядок элемента.
Нужно одним запросом сформировать путь, получающийся при обходе в глубину.
То есть если у нас такой вид:
1 0 1
2 0 2
3 1 1
4 1 2
5 2 1
6 0 3

То выведется
1 3 4 2 5 6
Нужно на чистом mysql без использования php и тд.
Заранее спасибо
P.S. Менять в структуре, к сожалению, ничего нельзя
Заранее спасибо

A: В MySQL нет штатных средств для работы с рекурсивными запросами. Но как известно, если очень хочется, то можно (хотя выглядит это жутковато и оптимизации по скорости это не поддается):
select id,path
  from (
   select  @path:=if(@id!=id,`index`,
             coalesce(
               (select concat(`index`,'/',@path)
                  from Tree1 where id=@pid)
             ,@path)
           ) path,
           @pid:=if(@id!=id,parent,
             (select parent from Tree1 N
               where id=@pid)
             ),
            @id:=id id, N
     from Tree1 T,
          (select @n:=@n+1 N
             from Tree1,(select @n:=0) N limit 3) Seq,
          (select @id:=0,@path:='') X
    order by id, N
  ) X
 where N=3
 order by path

Так как ни рекурсии ни циклов в обычном смысле слов нет, то запрос эмулирует рекурсию с помощью эмуляции цикла. В качестве цикла используется склейка с любой таблицей, в которой записей не менее, чем максимально возможный уровень иерархии в дереве. В данном примере используется выборка из той же самой таблицы, явно ограниченная limit 3 (если вложенность дерева больше - число надо соответственно увеличить). Собственно данные из этой таблицы не берутся, а создаются порядковые номера (N).
После этой склейки у нас в выборке появляется по 3 записи с одним и тем же id. На каждой из них, с помощью переменных, мы получаем id очередной родительской ветки, углубляясь по дереву (так как переменные помнят значения, сформированные в предыдущей строке). Самое главное, что мы тут формируем это путь к данной записи в виде индексов сортировки (если index может быть более 9 то для правильной сортировки надо выравнивать его в пути до одинаковой длины с помощью lpad())
В какой то момент записи родителей заканчиваются, мы дошли до корня дерева, тогда подзапрос индекса родителя возвращает NULL и при этом с помощью coalesce мы сохраняем ранее сформированный путь. Таким образом в последней записи нашего "цикла" у нас гарантированно будет полный путь до данного листа дерева. Нам остается только убрать из выборки рабочие строки цикла с частично сформированными путями, т.е. выбрать только последние строки (where N=3) и отсортировать по пути индексов.

A: Чтобы вывести полный путь в одном запросе нужно использовать Nested Set Model. (Полная информация по ссылке)

Для построения пути можно использовать хранимую функцию. При
  процедурном языке мы можем начать в нижней части дерева и перебирать
  вверх, чтобы вернуть полное дерево или единственный путь.

https://web.archive.org/web/20110606032941/http://dev.mysql.com/tech-resources/articles/hierarchical-data.html


text:
Q: Java can't open file in CentOS 6.5 I'm trying to run a java command prompt program that receives a path to a 5GB csv file.
While the path is guaranteed to be the right one and I'm running the program as root my program throws:
 (No such file or directory)ava.io.FileNotFoundException: /data/tmp/NPPES/npidata.csv
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at java.io.FileInputStream.<init>(FileInputStream.java:101)
    at java.io.FileReader.<init>(FileReader.java:58)
    ...

the java line is:
BufferedReader file = new BufferedReader( new FileReader(args[1]));

the file listing:
-rw-r--r-- 1 root root          4 Mar 11 15:35 empty.csv
-rw-r--r-- 1 root root 5097950480 Feb 11 00:36 npidata.csv

Then I thought it might be the file size so I created a 4 character file. Still nothing.
Has anyone by any chance experienced this before?
Update:
I modified the java program to list all the receiving arguments and they displayed correctly.
I was running the program through a shell script launch.sh with the following content:
#!/bin/sh
#echo on
java -Xmx16000M -XX:MaxPermSize=512M -classpath "../classes:../lib/*" $@

When I ran it directly with java it worked: the file was found.
The greatest mistery is that the cmd line params displayed correctly in both situations.
I wonder if shell is actually adding some funny unseen chars to those params.

A: As you can see on your file listing, only the root as the right to write on the file. Which means also that only the root can open it.
I think your application is not running as root so you should first try to change the right on your files :

chmod 666 This commande will allow everyone to read and write the files.

Sincerely,


text:
Q: Modifying lambda Expression> to Expression in an LINQ to Entities safe way At the bottom is an example of a left join implementation. It will work for normal lists and arrays but it will not work with LINQ to entities since I use Expression.Invoke().
What I'm trying to achieve is modifying/wrapping the resultSelector input to accept a single instance of the anonymous class 'a (used by the leftJoin queryable) instead of two separate parameters.
Inspecting resultSelector it seems I will want to create a modified version of it that has one parameter of type 'a and two arguments extracted from the properties Outer and Inner on 'a.
How do I go about doing this modification? How do I change Arguments?

[TestClass]
public class LeftJoinTests
{
    public class Outer
    {
        public int Key { get; }
        public int? ForeignKey { get; }

        public Outer(int key, int? foreignKey)
        {
            Key = key;
            ForeignKey = foreignKey;
        }
    }

    public class Inner
    {
        public int Key { get; }
        public string Data { get; }

        public Inner(int key, string data)
        {
            Key = key;
            Data = data;
        }
    }

    [TestMethod]
    public void LeftJoinTest()
    {
        var outers = new []
        {
            new Outer(1, 1),
            new Outer(2, 2),
            new Outer(3, 3),
            new Outer(4, null),
        };

        var inners = new []
        {
            new Inner(5, "5"),
            new Inner(2, "2"),
            new Inner(1, "1")
        };

        var leftJoin = LeftJoin(outers.AsQueryable(), inners.AsQueryable(), o => o.ForeignKey, i => i.Key, (oooo, iiii) => new { Outer = oooo, Inner = iiii }).ToArray();

        Assert.AreEqual(4, leftJoin.Length);

        Assert.AreSame(outers[0], leftJoin[0].Outer);
        Assert.AreSame(outers[1], leftJoin[1].Outer);
        Assert.AreSame(outers[2], leftJoin[2].Outer);
        Assert.AreSame(outers[3], leftJoin[3].Outer);

        Assert.AreSame(inners[2], leftJoin[0].Inner);
        Assert.AreSame(inners[1], leftJoin[1].Inner);
        Assert.IsNull(leftJoin[2].Inner);
        Assert.IsNull(leftJoin[3].Inner);
    }

    public IQueryable<TResult> LeftJoin<TOuter, TInner, TKey, TResult>(
        IQueryable<TOuter> outer,
        IQueryable<TInner> inner,
        Expression<Func<TOuter, TKey>> outerKeySelector,
        Expression<Func<TInner, TKey>> innerKeySelector,
        Expression<Func<TOuter, TInner, TResult>> resultSelector)
    {
        var leftJoin = outer.GroupJoin(
            inner,
            outerKeySelector,
            innerKeySelector,
            (o, i) => new
            {
                Outer = o,
                Inners = i
            }).SelectMany(
                oi => oi.Inners.DefaultIfEmpty(),
                (oi, i) => new
                {
                    oi.Outer,
                    Inner = i
                }
            );

        // Break the anonymous type of the left join into the two parameters needed for the resultSelector
        var anonymousType = leftJoin.GetType().GetGenericArguments()[0];
        var parameter = Expression.Parameter(anonymousType, "oi");

        var outerProperty = Expression.Property(parameter, "Outer");
        var outerLambda = Expression.Lambda(outerProperty, parameter);

        var innerProperty = Expression.Property(parameter, "Inner");
        var innerLambda = Expression.Lambda(innerProperty, parameter);

        var wrapper = Expression.Lambda(Expression.Invoke(resultSelector, new Expression[] {
            Expression.Invoke(outerLambda, parameter),
            Expression.Invoke(innerLambda, parameter)
        }), parameter);

        Expression<Func<TAnonymous, TResult>> Cast<TAnonymous>(Expression expression, IQueryable<TAnonymous> queryable)
        {
            return expression as Expression<Func<TAnonymous, TResult>>;
        }

        var typeSafeWrapper = Cast(wrapper, leftJoin);

        return leftJoin.Select(typeSafeWrapper);
    }
}

A: Using an ExpressionVisitor, you can replace Expression.Invoke when just substituting parameters, with actually replacing occurrences of the paramaters with the new expressions.
Here is the Replace method - it replaces a (reference) equal expression with another expression.
public static class ExpressionExt {
    /// <summary>
    /// Replaces an Expression (reference Equals) with another Expression
    /// </summary>
    /// <param name="orig">The original Expression.</param>
    /// <param name="from">The from Expression.</param>
    /// <param name="to">The to Expression.</param>
    /// <returns>Expression with all occurrences of from replaced with to</returns>
    public static Expression Replace(this Expression orig, Expression from, Expression to) => new ReplaceVisitor(from, to).Visit(orig);
}

/// <summary>
/// ExpressionVisitor to replace an Expression (that is Equals) with another Expression.
/// </summary>
public class ReplaceVisitor : ExpressionVisitor {
    readonly Expression from;
    readonly Expression to;

    public ReplaceVisitor(Expression from, Expression to) {
        this.from = from;
        this.to = to;
    }

    public override Expression Visit(Expression node) => node == from ? to : base.Visit(node);
}

With this available, you can replace the Expression.Invoke with replacing the parameters in the body with the new desired expressions:
public IQueryable<TResult> LeftJoin<TOuter, TInner, TKey, TResult>(
    IQueryable<TOuter> outer,
    IQueryable<TInner> inner,
    Expression<Func<TOuter, TKey>> outerKeySelector,
    Expression<Func<TInner, TKey>> innerKeySelector,
    Expression<Func<TOuter, TInner, TResult>> resultSelector) {
    var leftJoin = outer.GroupJoin(
        inner,
        outerKeySelector,
        innerKeySelector,
        (o, i) => new {
            Outer = o,
            Inners = i
        }).SelectMany(
            oi => oi.Inners.DefaultIfEmpty(),
            (oi, i) => new {
                oi.Outer,
                Inner = i
            }
        );

    // Break the anonymous type of the left join into the two parameters needed for the resultSelector
    var anonymousType = leftJoin.GetType().GetGenericArguments()[0];
    var parameter = Expression.Parameter(anonymousType, "oi");
    // oi.Outer
    var outerProperty = Expression.Property(parameter, "Outer");
    // oi.Inner
    var innerProperty = Expression.Property(parameter, "Inner");

    // resultSelector = (o,i) => expr(o,i)
    // o
    var resultOuterParm = resultSelector.Parameters[0];
    // i
    var resultInnerParm = resultSelector.Parameters[1];
    // expr(o,i) --> expr(oi.Outer, oi.Inner)
    var newBody = resultSelector.Body.Replace(resultOuterParm, outerProperty).Replace(resultInnerParm, innerProperty);

    // oi => expr(oi.Outer, oi.Inner)
    Expression<Func<TAnonymous, TResult>> typeSafeLambda<TAnonymous>(IQueryable<TAnonymous> _) =>
        Expression.Lambda<Func<TAnonymous, TResult>>(newBody, parameter);

    var wrapper = typeSafeLambda(leftJoin);

    return leftJoin.Select(wrapper);
}


text:
Q: Can you only inject services into services through bootstrap? I am trying to wire up a basic Angular2 app that uses the Http service. (Most of the tutorials I've seen do this by having a Component consume the Http service, which seems wrong unless the basic philosophy of thin controllers has changed – but that's a different question.)
I would like to create a service that uses Angular's Http service. But I can't figure out how to inject the Http service other than this:
boot.ts:
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
import {HTTP_PROVIDERS } from 'angular2/http';

bootstrap(AppComponent, [HTTP_PROVIDERS]);

myService.ts:
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';

@Injectable()
export class aService{
    constructor(http:Http){
    }
    /** do some stuff *//
}

This works, but it seem very wrong to require the user of the service to know the service's dependencies and be required to inject them into the bootstrap process. It seems like there should be a way to directly hand a providers array to a service the same way you can a component, but I can't find it. Am I just missing something?

A: Update
This way if a parent injector provides an implementation for OtherService this one is used, otherwise OtherServiceImpl is used (default).
@Injectable()
class SomeService {
  OtherService _other;

  SomeService(Injector injector) {
    _other = injector.getOptional(OtherService);
    if (_other == null) {
      _other = injector.resolveAndCreateChild([
        provide(OtherService, useClass: OtherServiceImpl)
      ]).get(OtherService);
    }
    _other.doSomething();
  }
}

If you provide another one like
bootstrap(AppElement, [
  provide(OtherService, useClass: OtherServiceImpl2)
]);

OtherServiceImpl2 is used.
See also https://github.com/angular/angular/issues/5622
Original
You could just make the http service optional (using the @Optional() annotation) and if none is provided just create an instance inside the constructor with new Http().
This way the user doesn't need to know about the services dependencies, but is able to pass alternative implementations if necessary (for example for testing).
If creating the dependeny inside the service requires DI itself, you can inject an injector and use it to get dependencies.
See also optional dependencies in http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html
What also could work (not tried myself yet) is just to create a child injector and instruct it to skip self
From the SkipSelfMetadata documentation
  class Dependency {
  }

  @Injectable()
  class NeedsDependency {
    dependency;
    constructor(@SkipSelf() dependency:Dependency) {
      this.dependency = dependency;
    }
  }

  var parent = Injector.resolveAndCreate([Dependency]);
  var child = parent.resolveAndCreateChild([NeedsDependency]);
  expect(child.get(NeedsDependency).dependency instanceof Depedency).toBe(true);

  var inj = Injector.resolveAndCreate([Dependency, NeedsDependency]);
  expect(() => inj.get(NeedsDependency)).toThrowError();

I don't know yet if this still resolves from "self" if parent can't provide the requested type.