问:
Find which element of the stream does not match the given predicate in allmatch
I want to find out which element is failing the predicate in case of allmatch.

```<code>List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
boolean isEven = numbers.stream().allMatch(n-> n % 2 == 0);
</code>```

Here isEven is false, as element 1 fails the predicate.

I can use forEach over the stream to find which element fails like:

```<code>numbers.stream().forEach(n -> {
            if (n % 2 != 0)
                System.out.println(n + "is Odd");
        });
</code>```

Is there a way to figure out which elements fails the predicate in the allmatch when it returns false?

答:
You need to split this two action (filtering out and verifying all match into two actions)</p>

```<code>List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> notMatched = numbers
                            .stream()
                            .filter(n-> n % 2 != 0)
                            .collect(Collectors.toList());
boolean isEven = notMatched.isEmpty();
</code>```

Body:
I want to find out which element is failing the predicate in case of allmatch.

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
boolean isEven = numbers.stream().allMatch(n-> n % 2 == 0);

Here isEven is false, as element 1 fails the predicate.

I can use forEach over the stream to find which element fails like:

numbers.stream().forEach(n -> {
            if (n % 2 != 0)
                System.out.println(n + "is Odd");
        });

Is there a way to figure out which elements fails the predicate in the allmatch when it returns false?

Body:
You need to split this two action (filtering out and verifying all match into two actions)

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> notMatched = numbers
                            .stream()
                            .filter(n-> n % 2 != 0)
                            .collect(Collectors.toList());
boolean isEven = notMatched.isEmpty();


来源: stackexchange

问:
Devanagari text rendering improperly in PyGame
We have a small web app that we want to convert into something native. Right now, it's got a lot of moving parts (the backend, the browser etc.) and we'd like to convert it into a single tight application. We decided to use PyGame to do this and it's been fine so far except for a font rendering issue.

The string I'd like to render is कोझिकोड. This, correctly rendered looks like .

The specific code points are \u0915 \u094b \u091d \u093f \u0915 \u094b and \u0921

Now, this looks fine in my editor and my browser but when I try to render it in PyGame, I get this . Basically, the vowel sign  (\u093f ि) should have been on the left of the झ but it appears to its right (and to the left of the क) thereby messing it up completely. This doesn't happen in a browser or a text editor (with the same input string) so I'm guessing it a renderer problem in PyGame.

There is one crude fix which works only in this specific case which i s to put the  ि (\u093f) before the झ (\u091d). In that case, it renders properly like so . This relies on me knowing something about the language and putting that logic into the code. I have to deal with multiple languages here so that's not really feasible.

I don't have much experience with unicode so I don't know how to approach this problem. Is there something I can do to fix this?

In case it matters, I'm using the freesans font which is there on Debian and which has the necessary glyphs to render this.

Update:
The code to actually render this is as follows

```<code># -*- coding: utf-8 -*-
import time

import pygame

# Pygame setup and create root window
pygame.font.init()
screen = pygame.display.set_mode((320, 200))
empty = pygame.Surface((320, 200))

font_file = pygame.font.match_font("freesans")  # Select and
font = pygame.font.Font(font_file, 30)          # open the font
writing = font.render(u"कोिझकोड  कोझिकोड", True, (0, 0, 0))  # Render text on a surface
screen.fill((255, 255, 255)) # Clear the background
screen.blit(writing, (10, 10)) # Blit the text surface on the background
pygame.display.flip()  # Refresh the display

input() # Wait for input before quitting
</code>```

This is what it looks like

The first word is rendered correctly but we've done it by inverting the vowel and the letter positions as I mentioned in the crude fix. The second is written properly but not rendered correctly.

Update 2:
In the absence of anything else, I've decided to try to render the string into an image using an external program and then blit this image onto the PyGame Surface. I tried imagemagick but it messes us in the same way as this. Gimp works fine and so I'm planning to use the batch mode to get my work done.

答: I had to finally resort to a really ugly but usable workaround for my own situation. I wrote a script-fu plugin which takes a filename and a piece of text as arguments. It then writes out the text and saves it a png file using gimp. My program then loads this up and blits the png directly onto the surface.

ContentLicense: CC BY-SA 3.0

Body:
We have a small web app that we want to convert into something native. Right now, it's got a lot of moving parts (the backend, the browser etc.) and we'd like to convert it into a single tight application. We decided to use PyGame to do this and it's been fine so far except for a font rendering issue.

The string I'd like to render is कोझिकोड. This, correctly rendered looks like .

The specific code points are \u0915 \u094b \u091d \u093f \u0915 \u094b and \u0921

Now, this looks fine in my editor and my browser but when I try to render it in PyGame, I get this . Basically, the vowel sign  (\u093f ि) should have been on the left of the झ but it appears to its right (and to the left of the क) thereby messing it up completely. This doesn't happen in a browser or a text editor (with the same input string) so I'm guessing it a renderer problem in PyGame.

There is one crude fix which works only in this specific case which i s to put the  ि (\u093f) before the झ (\u091d). In that case, it renders properly like so . This relies on me knowing something about the language and putting that logic into the code. I have to deal with multiple languages here so that's not really feasible.

I don't have much experience with unicode so I don't know how to approach this problem. Is there something I can do to fix this?

In case it matters, I'm using the freesans font which is there on Debian and which has the necessary glyphs to render this.

Update:
The code to actually render this is as follows

# -*- coding: utf-8 -*-
import time

import pygame

# Pygame setup and create root window
pygame.font.init()
screen = pygame.display.set_mode((320, 200))
empty = pygame.Surface((320, 200))

font_file = pygame.font.match_font("freesans")  # Select and
font = pygame.font.Font(font_file, 30)          # open the font
writing = font.render(u"कोिझकोड  कोझिकोड", True, (0, 0, 0))  # Render text on a surface
screen.fill((255, 255, 255)) # Clear the background
screen.blit(writing, (10, 10)) # Blit the text surface on the background
pygame.display.flip()  # Refresh the display

input() # Wait for input before quitting

This is what it looks like

The first word is rendered correctly but we've done it by inverting the vowel and the letter positions as I mentioned in the crude fix. The second is written properly but not rendered correctly.

Update 2:
In the absence of anything else, I've decided to try to render the string into an image using an external program and then blit this image onto the PyGame Surface. I tried imagemagick but it messes us in the same way as this. Gimp works fine and so I'm planning to use the batch mode to get my work done.


问:
GKE + WebSocket + NodePort 30s dropped connections
I have a golang service that implements a WebSocket client using gorilla that is exposed to a Google Container Engine (GKE)/k8s cluster via a NodePort (30002 in this case).

I've got a manually created load balancer (i.e. NOT at k8s ingress/load balancer) with HTTP/HTTPS frontends (i.e. 80/443) that forward traffic to nodes in my GKE/k8s cluster on port 30002.

I can get my JavaScript WebSocket implementation in the browser (Chrome 58.0.3029.110 on OSX) to connect, upgrade and send / receive messages.

I log ping/pongs in the golang WebSocket client and all looks good until 30s in. 30s after connection my golang WebSocket client gets an EOF / close 1006 (abnormal closure) and my JavaScript code gets a close event. As far as I can tell, neither my Golang or JavaScript code is initiating the WebSocket closure.

I don't particularly care about session affinity in this case AFAIK, but I have tried both IP and cookie based affinity in the load balancer with long lived cookies.

Additionally, this exact same set of k8s deployment/pod/service specs and golang service code works great on my KOPS based k8s cluster on AWS through AWS' ELBs.

Any ideas where the 30s forced closures might be coming from? Could that be a k8s default cluster setting specific to GKE or something on the GCE load balancer?

Thanks for reading!

-- UPDATE --

There is a backend configuration timeout setting on the load balancer which is for "How long to wait for the backend service to respond before considering it a failed request".

The WebSocket is not unresponsive. It is sending ping/pong and other messages right up until getting killed which I can verify by console.log's in the browser and logs in the golang service.

That said, if I bump the load balancer backend timeout setting to 30000 seconds, things "work".

Doesn't feel like a real fix though because the load balancer will continue to feed actual unresponsive services traffic inappropriately, never mind if the WebSocket does become unresponsive.

I've isolated the high timeout setting to a specific backend setting using a path map, but hoping to come up with a real fix to the problem.

答:
I think this may be Working as Intended. Google just updated the documentation today (about an hour ago).

LB Proxy Support docs

Backend Service Components docs

Cheers,

Matt


问:
PHP, adding time to date();?
I have used this to get the server date,

```<code>$yd = getdate();

echo $yd['year'];
echo $yd['mon'];
echo $yd['mday'];
</code>```

...but how do I add something to it. For example, I want to know what date it will be in 7 days.

Thanks!

答:
```<code>echo date("Y-m-d",strtotime("+7 days"));
</code>```

ContentLicense: CC BY-SA 2.5

Title: PHP, adding time to date();?

Body:
I have used this to get the server date,

$yd = getdate();

echo $yd['year'];
echo $yd['mon'];
echo $yd['mday'];

...but how do I add something to it. For example, I want to know what date it will be in 7 days.

Thanks!


问:
I have error with my android app
I'm new developer in android development i have two apps in play store but my apps now is not working with android 6 & android 7 i get this messages

runtimeException
  and NullPointerException

this my main activity code i have problem with:

```<code>public class Recored extends Activity {

Button rec,stop;
private MediaRecorder myRecords;
private String outputFile = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recored);

    stop = (Button)findViewById(R.id.bStop);
    rec = (Button)findViewById(R.id.bRecord);

    stop.setEnabled(false);
    myRecords = new MediaRecorder();
    myRecords.setAudioSource(MediaRecorder.AudioSource.MIC);
    myRecords.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    myRecords.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    Date createdDate = new Date();
    File myDir = new File(Environment.getExternalStorageDirectory()+"/Recordings");
    if (!myDir.exists()){
        if (myDir.mkdir());
    }
        outputFile = myDir.getAbsolutePath() + "/" + createdDate + ".mp3";
        myRecords.setOutputFile(outputFile);

        rec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    myRecords.prepare();
                    myRecords.start();

                }

                catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
                rec.setEnabled(false);
                stop.setEnabled(true);
                Toast.makeText(getApplicationContext(),"Recording started",Toast.LENGTH_LONG).show();
            }
        });
        stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myRecords.stop();
                myRecords.release();
                myRecords = null;
                stop.setEnabled(false);
                rec.setEnabled(true);
            }
        });

}
</code>```

}

答:
Did you ask for Run-time permission?

```<code> private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200;

  private String[] permissions = {Manifest.permission.RECORD_AUDIO};
</code>```

// Add this code to OnCreate

```<code>ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);
</code>```

Override this method

```<code>  @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQUEST_RECORD_AUDIO_PERMISSION:
                permissionToRecordAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                break;
        }
        if (!permissionToRecordAccepted) finish();

    }
</code>```

Title: I have error with my android app

Body:
I'm new developer in android development i have two apps in play store but my apps now is not working with android 6 & android 7 i get this messages

runtimeException
  and NullPointerException

this my main activity code i have problem with:

public class Recored extends Activity {

Button rec,stop;
private MediaRecorder myRecords;
private String outputFile = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recored);

    stop = (Button)findViewById(R.id.bStop);
    rec = (Button)findViewById(R.id.bRecord);

    stop.setEnabled(false);
    myRecords = new MediaRecorder();
    myRecords.setAudioSource(MediaRecorder.AudioSource.MIC);
    myRecords.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    myRecords.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    Date createdDate = new Date();
    File myDir = new File(Environment.getExternalStorageDirectory()+"/Recordings");
    if (!myDir.exists()){
        if (myDir.mkdir());
    }
        outputFile = myDir.getAbsolutePath() + "/" + createdDate + ".mp3";
        myRecords.setOutputFile(outputFile);

        rec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    myRecords.prepare();
                    myRecords.start();

                }

                catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
                rec.setEnabled(false);
                stop.setEnabled(true);
                Toast.makeText(getApplicationContext(),"Recording started",Toast.LENGTH_LONG).show();
            }
        });
        stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myRecords.stop();
                myRecords.release();
                myRecords = null;
                stop.setEnabled(false);
                rec.setEnabled(true);
            }
        });

}

}

Body:
Did you ask for Run-time permission?

 private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200;

  private String[] permissions = {Manifest.permission.RECORD_AUDIO};

// Add this code to OnCreate

ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);

Override this method

  @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQUEST_RECORD_AUDIO_PERMISSION:
                permissionToRecordAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                break;
        }
        if (!permissionToRecordAccepted) finish();

    }


问:
What may be the reason for loss can not go further down when training multi-class nn using keras
I am training a multi-class neural network by using keras (backend is tensorflow). I will give my settings and some codes at final position.

The description is:
When I do 10 folders cross-validation, the training loss and validation loss goes down at first 10-15 epochs, but can not go further down after 15 epochs and staying on about (loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774).

I have tried several changes for my settings. For example, add hidden layers, add normalization.BatchNormalization(), change optimizer from adam to sgd or rmsprop, change loss function from categorical_crossentropy to others. But no effect.

I would like to discuss what are the probable reasons for this kind of things. I would be very happy if there is a summary document or presentation here.

My data has 10000 rows. And feature has 507 attributes of 0/1. Labels are multi-class with classes num = 7. The balance between classes is almost OK, because I selected the 10000 data from a more large dataset.

My model is as follows:

```<code>model = Sequential()
model.add(Dense(500, activation='relu', input_dim=self.feature_dim,
kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(100, activation='relu'))
model.add(Dense(self.label_dim, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
</code>```

Some logs as follows:

```<code>Running Fold 1/10
Train on 9534 samples, validate on 1060 samples
Epoch 1/100
1000/9534 [==>...........................] - ETA: 7s - loss: 6.9644 - acc: 0.1150
2000/9534 [=====>........................] - ETA: 3s - loss: 6.8357 - acc: 0.1715
3000/9534 [========>.....................] - ETA: 2s - loss: 6.7147 - acc: 0.2243
4000/9534 [===========>..................] - ETA: 1s - loss: 6.5922 - acc: 0.2683
5000/9534 [==============>...............] - ETA: 1s - loss: 6.4779 - acc: 0.2908
6000/9534 [=================>............] - ETA: 0s - loss: 6.3618 - acc: 0.3097
7000/9534 [=====================>........] - ETA: 0s - loss: 6.2513 - acc: 0.3244
8000/9534 [========================>.....] - ETA: 0s - loss: 6.1465 - acc: 0.3340
9000/9534 [===========================>..] - ETA: 0s - loss: 6.0439 - acc: 0.3411
9534/9534 [==============================] - 1s - loss: 5.9900 - acc: 0.3442 - val_loss: 4.8716 - val_acc: 0.4377
Epoch 2/100
1000/9534 [==>...........................] - ETA: 0s - loss: 4.8370 - acc: 0.4340
2000/9534 [=====>........................] - ETA: 0s - loss: 4.7593 - acc: 0.4415
3000/9534 [========>.....................] - ETA: 0s - loss: 4.6923 - acc: 0.4423
4000/9534 [===========>..................] - ETA: 0s - loss: 4.6176 - acc: 0.4557
5000/9534 [==============>...............] - ETA: 0s - loss: 4.5517 - acc: 0.4642
6000/9534 [=================>............] - ETA: 0s - loss: 4.4809 - acc: 0.4703
7000/9534 [=====================>........] - ETA: 0s - loss: 4.4036 - acc: 0.4804
8000/9534 [========================>.....] - ETA: 0s - loss: 4.3364 - acc: 0.4821
9000/9534 [===========================>..] - ETA: 0s - loss: 4.2652 - acc: 0.4901
9534/9534 [==============================] - 1s - loss: 4.2316 - acc: 0.4928 - val_loss: 3.5151 - val_acc: 0.5179
Epoch 3/100
1000/9534 [==>...........................] - ETA: 1s - loss: 3.4892 - acc: 0.5370
2000/9534 [=====>........................] - ETA: 1s - loss: 3.4573 - acc: 0.5395
3000/9534 [========>.....................] - ETA: 0s - loss: 3.4006 - acc: 0.5450
4000/9534 [===========>..................] - ETA: 0s - loss: 3.3430 - acc: 0.5435
5000/9534 [==============>...............] - ETA: 0s - loss: 3.2929 - acc: 0.5448
6000/9534 [=================>............] - ETA: 0s - loss: 3.2414 - acc: 0.5448
7000/9534 [=====================>........] - ETA: 0s - loss: 3.1959 - acc: 0.5446
8000/9534 [========================>.....] - ETA: 0s - loss: 3.1489 - acc: 0.5485
9000/9534 [===========================>..] - ETA: 0s - loss: 3.1021 - acc: 0.5501
9534/9534 [==============================] - 1s - loss: 3.0832 - acc: 0.5481 - val_loss: 2.6184 - val_acc: 0.5349
Epoch 4/100
1000/9534 [==>...........................] - ETA: 1s - loss: 2.5950 - acc: 0.5640
2000/9534 [=====>........................] - ETA: 1s - loss: 2.5570 - acc: 0.5705
3000/9534 [========>.....................] - ETA: 0s - loss: 2.5197 - acc: 0.5743
4000/9534 [===========>..................] - ETA: 0s - loss: 2.4929 - acc: 0.5650
5000/9534 [==============>...............] - ETA: 0s - loss: 2.4703 - acc: 0.5646
6000/9534 [=================>............] - ETA: 0s - loss: 2.4388 - acc: 0.5648
7000/9534 [=====================>........] - ETA: 0s - loss: 2.4054 - acc: 0.5680
8000/9534 [========================>.....] - ETA: 0s - loss: 2.3798 - acc: 0.5649
9000/9534 [===========================>..] - ETA: 0s - loss: 2.3522 - acc: 0.5662
9534/9534 [==============================] - 1s - loss: 2.3342 - acc: 0.5685 - val_loss: 2.0442 - val_acc: 0.5491
Epoch 5/100
1000/9534 [==>...........................] - ETA: 0s - loss: 2.0090 - acc: 0.5830
2000/9534 [=====>........................] - ETA: 0s - loss: 1.9990 - acc: 0.5865
3000/9534 [========>.....................] - ETA: 0s - loss: 1.9812 - acc: 0.5833
4000/9534 [===========>..................] - ETA: 0s - loss: 1.9558 - acc: 0.5835
5000/9534 [==============>...............] - ETA: 0s - loss: 1.9377 - acc: 0.5832
6000/9534 [=================>............] - ETA: 0s - loss: 1.9173 - acc: 0.5832
7000/9534 [=====================>........] - ETA: 0s - loss: 1.8968 - acc: 0.5850
8000/9534 [========================>.....] - ETA: 0s - loss: 1.8759 - acc: 0.5851
9000/9534 [===========================>..] - ETA: 0s - loss: 1.8582 - acc: 0.5846
9534/9534 [==============================] - 1s - loss: 1.8501 - acc: 0.5834 - val_loss: 1.6868 - val_acc: 0.5500
Epoch 6/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.6716 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.6387 - acc: 0.5910
3000/9534 [========>.....................] - ETA: 0s - loss: 1.6163 - acc: 0.5910
4000/9534 [===========>..................] - ETA: 0s - loss: 1.6130 - acc: 0.5882
5000/9534 [==============>...............] - ETA: 0s - loss: 1.5982 - acc: 0.5890
6000/9534 [=================>............] - ETA: 0s - loss: 1.5861 - acc: 0.5892
7000/9534 [=====================>........] - ETA: 0s - loss: 1.5724 - acc: 0.5914
8000/9534 [========================>.....] - ETA: 0s - loss: 1.5578 - acc: 0.5922
9000/9534 [===========================>..] - ETA: 0s - loss: 1.5492 - acc: 0.5904
9534/9534 [==============================] - 0s - loss: 1.5468 - acc: 0.5893 - val_loss: 1.4677 - val_acc: 0.5585
Epoch 7/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.4380 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.4332 - acc: 0.5900
3000/9534 [========>.....................] - ETA: 0s - loss: 1.4208 - acc: 0.5957
4000/9534 [===========>..................] - ETA: 0s - loss: 1.4073 - acc: 0.5985
5000/9534 [==============>...............] - ETA: 0s - loss: 1.4027 - acc: 0.5960
6000/9534 [=================>............] - ETA: 0s - loss: 1.3922 - acc: 0.5950
7000/9534 [=====================>........] - ETA: 0s - loss: 1.3842 - acc: 0.5951
8000/9534 [========================>.....] - ETA: 0s - loss: 1.3729 - acc: 0.5988
9000/9534 [===========================>..] - ETA: 0s - loss: 1.3611 - acc: 0.6012
9534/9534 [==============================] - 1s - loss: 1.3588 - acc: 0.6015 - val_loss: 1.3387 - val_acc: 0.5717
Epoch 8/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.3429 - acc: 0.5750
2000/9534 [=====>........................] - ETA: 0s - loss: 1.3071 - acc: 0.5980
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2915 - acc: 0.6007
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2834 - acc: 0.5977
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2791 - acc: 0.6008
6000/9534 [=================>............] - ETA: 0s - loss: 1.2636 - acc: 0.6043
7000/9534 [=====================>........] - ETA: 0s - loss: 1.2521 - acc: 0.6049
8000/9534 [========================>.....] - ETA: 0s - loss: 1.2495 - acc: 0.6041
9000/9534 [===========================>..] - ETA: 0s - loss: 1.2506 - acc: 0.6031
9534/9534 [==============================] - 1s - loss: 1.2491 - acc: 0.6022 - val_loss: 1.2617 - val_acc: 0.5698
Epoch 9/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1627 - acc: 0.6240
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1709 - acc: 0.6235
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2001 - acc: 0.6127
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2000 - acc: 0.6098
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2002 - acc: 0.6096
6000/9534 [=================>............] - ETA: 0s - loss: 1.1969 - acc: 0.6085
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1894 - acc: 0.6117
9534/9534 [==============================] - 1s - loss: 1.1793 - acc: 0.6094 - val_loss: 1.2151 - val_acc: 0.5679
Epoch 10/100
1000/9534 [==>...........................] - ETA: 1s - loss: 1.1436 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1369 - acc: 0.6260
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1366 - acc: 0.6207
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6210
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1276 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.1289 - acc: 0.6217
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1321 - acc: 0.6180
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1352 - acc: 0.6150
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1341 - acc: 0.6141
9534/9534 [==============================] - 0s - loss: 1.1349 - acc: 0.6129 - val_loss: 1.1946 - val_acc: 0.5632
Epoch 11/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1684 - acc: 0.5930
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1338 - acc: 0.6075
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1177 - acc: 0.6140
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6075
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1235 - acc: 0.6154
6000/9534 [=================>............] - ETA: 0s - loss: 1.1188 - acc: 0.6173
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1147 - acc: 0.6179
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1068 - acc: 0.6196
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1090 - acc: 0.6190
9534/9534 [==============================] - 0s - loss: 1.1092 - acc: 0.6177 - val_loss: 1.1788 - val_acc: 0.5689
Epoch 12/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0702 - acc: 0.6280
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0742 - acc: 0.6280
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0821 - acc: 0.6237
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0868 - acc: 0.6233
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0807 - acc: 0.6258
6000/9534 [=================>............] - ETA: 0s - loss: 1.0884 - acc: 0.6208
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0905 - acc: 0.6187
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0895 - acc: 0.6205
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0899 - acc: 0.6200
9534/9534 [==============================] - 1s - loss: 1.0900 - acc: 0.6205 - val_loss: 1.1598 - val_acc: 0.5830
Epoch 13/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0730 - acc: 0.6340
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0649 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0600 - acc: 0.6430
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0718 - acc: 0.6350
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0821 - acc: 0.6280
6000/9534 [=================>............] - ETA: 0s - loss: 1.0779 - acc: 0.6295
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0713 - acc: 0.6316
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0737 - acc: 0.6289
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0767 - acc: 0.6261
9534/9534 [==============================] - 1s - loss: 1.0752 - acc: 0.6259 - val_loss: 1.1589 - val_acc: 0.5642
Epoch 14/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0148 - acc: 0.6520
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0395 - acc: 0.6430
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0503 - acc: 0.6377
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0521 - acc: 0.6382
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0529 - acc: 0.6388
6000/9534 [=================>............] - ETA: 0s - loss: 1.0519 - acc: 0.6392
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0561 - acc: 0.6359
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0547 - acc: 0.6332
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0591 - acc: 0.6313
9534/9534 [==============================] - 0s - loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774
Epoch 15/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0513 - acc: 0.6410
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0635 - acc: 0.6245
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0500 - acc: 0.6280
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0530 - acc: 0.6257
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0585 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.0562 - acc: 0.6233
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0507 - acc: 0.6267
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0540 - acc: 0.6267
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0513 - acc: 0.6286
9534/9534 [==============================] - 0s - loss: 1.0492 - acc: 0.6290 - val_loss: 1.1608 - val_acc: 0.5802
Epoch 16/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0553 - acc: 0.6300
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0582 - acc: 0.6305
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0341 - acc: 0.6407
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0312 - acc: 0.6398
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0454 - acc: 0.6324
6000/9534 [=================>............] - ETA: 0s - loss: 1.0438 - acc: 0.6332
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0445 - acc: 0.6323
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0426 - acc: 0.6331
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0439 - acc: 0.6323
9534/9534 [==============================] - 0s - loss: 1.0427 - acc: 0.6323 - val_loss: 1.1544 - val_acc: 0.5764
Epoch 17/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0633 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0407 - acc: 0.6300
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0417 - acc: 0.6343
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0322 - acc: 0.6402
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0283 - acc: 0.6426
6000/9534 [=================>............] - ETA: 0s - loss: 1.0355 - acc: 0.6400
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0361 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0336 - acc: 0.6392
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0309 - acc: 0.6394
9534/9534 [==============================] - 0s - loss: 1.0342 - acc: 0.6382 - val_loss: 1.1575 - val_acc: 0.5755
Epoch 18/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0289 - acc: 0.6510
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0233 - acc: 0.6505
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0176 - acc: 0.6507
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0194 - acc: 0.6500
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0242 - acc: 0.6442
6000/9534 [=================>............] - ETA: 0s - loss: 1.0239 - acc: 0.6423
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0249 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0264 - acc: 0.6404
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0277 - acc: 0.6406
9534/9534 [==============================] - 0s - loss: 1.0299 - acc: 0.6389 - val_loss: 1.1597 - val_acc: 0.5708
Epoch 19/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0271 - acc: 0.6420
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0114 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0046 - acc: 0.6510
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0137 - acc: 0.6453
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0074 - acc: 0.6492
6000/9534 [=================>............] - ETA: 0s - loss: 1.0112 - acc: 0.6490
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0072 - acc: 0.6504
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0093 - acc: 0.6496
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0137 - acc: 0.6452
9534/9534 [==============================] - 0s - loss: 1.0159 - acc: 0.6451 - val_loss: 1.1603 - val_acc: 0.5651
</code>```

答:
cross validation code is as follows:

```<code>skf = KFold(n_splits=cross_validation, shuffle=True)
for train_index, test_index in skf.split(X):
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = Y[train_index], Y[test_index]
    model = None
    model = self.__create_model()
    model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(X_test, y_test))
</code>```

X and Y are two matrix with shape (10000, 507) and (10000, 7)

Body:
I am training a multi-class neural network by using keras (backend is tensorflow). I will give my settings and some codes at final position.

The description is:
When I do 10 folders cross-validation, the training loss and validation loss goes down at first 10-15 epochs, but can not go further down after 15 epochs and staying on about (loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774).

I have tried several changes for my settings. For example, add hidden layers, add normalization.BatchNormalization(), change optimizer from adam to sgd or rmsprop, change loss function from categorical_crossentropy to others. But no effect.

I would like to discuss what are the probable reasons for this kind of things. I would be very happy if there is a summary document or presentation here.

My data has 10000 rows. And feature has 507 attributes of 0/1. Labels are multi-class with classes num = 7. The balance between classes is almost OK, because I selected the 10000 data from a more large dataset.

My model is as follows:

model = Sequential()
model.add(Dense(500, activation='relu', input_dim=self.feature_dim,
kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(100, activation='relu'))
model.add(Dense(self.label_dim, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

Some logs as follows:

Running Fold 1/10
Train on 9534 samples, validate on 1060 samples
Epoch 1/100
1000/9534 [==>...........................] - ETA: 7s - loss: 6.9644 - acc: 0.1150
2000/9534 [=====>........................] - ETA: 3s - loss: 6.8357 - acc: 0.1715
3000/9534 [========>.....................] - ETA: 2s - loss: 6.7147 - acc: 0.2243
4000/9534 [===========>..................] - ETA: 1s - loss: 6.5922 - acc: 0.2683
5000/9534 [==============>...............] - ETA: 1s - loss: 6.4779 - acc: 0.2908
6000/9534 [=================>............] - ETA: 0s - loss: 6.3618 - acc: 0.3097
7000/9534 [=====================>........] - ETA: 0s - loss: 6.2513 - acc: 0.3244
8000/9534 [========================>.....] - ETA: 0s - loss: 6.1465 - acc: 0.3340
9000/9534 [===========================>..] - ETA: 0s - loss: 6.0439 - acc: 0.3411
9534/9534 [==============================] - 1s - loss: 5.9900 - acc: 0.3442 - val_loss: 4.8716 - val_acc: 0.4377
Epoch 2/100
1000/9534 [==>...........................] - ETA: 0s - loss: 4.8370 - acc: 0.4340
2000/9534 [=====>........................] - ETA: 0s - loss: 4.7593 - acc: 0.4415
3000/9534 [========>.....................] - ETA: 0s - loss: 4.6923 - acc: 0.4423
4000/9534 [===========>..................] - ETA: 0s - loss: 4.6176 - acc: 0.4557
5000/9534 [==============>...............] - ETA: 0s - loss: 4.5517 - acc: 0.4642
6000/9534 [=================>............] - ETA: 0s - loss: 4.4809 - acc: 0.4703
7000/9534 [=====================>........] - ETA: 0s - loss: 4.4036 - acc: 0.4804
8000/9534 [========================>.....] - ETA: 0s - loss: 4.3364 - acc: 0.4821
9000/9534 [===========================>..] - ETA: 0s - loss: 4.2652 - acc: 0.4901
9534/9534 [==============================] - 1s - loss: 4.2316 - acc: 0.4928 - val_loss: 3.5151 - val_acc: 0.5179
Epoch 3/100
1000/9534 [==>...........................] - ETA: 1s - loss: 3.4892 - acc: 0.5370
2000/9534 [=====>........................] - ETA: 1s - loss: 3.4573 - acc: 0.5395
3000/9534 [========>.....................] - ETA: 0s - loss: 3.4006 - acc: 0.5450
4000/9534 [===========>..................] - ETA: 0s - loss: 3.3430 - acc: 0.5435
5000/9534 [==============>...............] - ETA: 0s - loss: 3.2929 - acc: 0.5448
6000/9534 [=================>............] - ETA: 0s - loss: 3.2414 - acc: 0.5448
7000/9534 [=====================>........] - ETA: 0s - loss: 3.1959 - acc: 0.5446
8000/9534 [========================>.....] - ETA: 0s - loss: 3.1489 - acc: 0.5485
9000/9534 [===========================>..] - ETA: 0s - loss: 3.1021 - acc: 0.5501
9534/9534 [==============================] - 1s - loss: 3.0832 - acc: 0.5481 - val_loss: 2.6184 - val_acc: 0.5349
Epoch 4/100
1000/9534 [==>...........................] - ETA: 1s - loss: 2.5950 - acc: 0.5640
2000/9534 [=====>........................] - ETA: 1s - loss: 2.5570 - acc: 0.5705
3000/9534 [========>.....................] - ETA: 0s - loss: 2.5197 - acc: 0.5743
4000/9534 [===========>..................] - ETA: 0s - loss: 2.4929 - acc: 0.5650
5000/9534 [==============>...............] - ETA: 0s - loss: 2.4703 - acc: 0.5646
6000/9534 [=================>............] - ETA: 0s - loss: 2.4388 - acc: 0.5648
7000/9534 [=====================>........] - ETA: 0s - loss: 2.4054 - acc: 0.5680
8000/9534 [========================>.....] - ETA: 0s - loss: 2.3798 - acc: 0.5649
9000/9534 [===========================>..] - ETA: 0s - loss: 2.3522 - acc: 0.5662
9534/9534 [==============================] - 1s - loss: 2.3342 - acc: 0.5685 - val_loss: 2.0442 - val_acc: 0.5491
Epoch 5/100
1000/9534 [==>...........................] - ETA: 0s - loss: 2.0090 - acc: 0.5830
2000/9534 [=====>........................] - ETA: 0s - loss: 1.9990 - acc: 0.5865
3000/9534 [========>.....................] - ETA: 0s - loss: 1.9812 - acc: 0.5833
4000/9534 [===========>..................] - ETA: 0s - loss: 1.9558 - acc: 0.5835
5000/9534 [==============>...............] - ETA: 0s - loss: 1.9377 - acc: 0.5832
6000/9534 [=================>............] - ETA: 0s - loss: 1.9173 - acc: 0.5832
7000/9534 [=====================>........] - ETA: 0s - loss: 1.8968 - acc: 0.5850
8000/9534 [========================>.....] - ETA: 0s - loss: 1.8759 - acc: 0.5851
9000/9534 [===========================>..] - ETA: 0s - loss: 1.8582 - acc: 0.5846
9534/9534 [==============================] - 1s - loss: 1.8501 - acc: 0.5834 - val_loss: 1.6868 - val_acc: 0.5500
Epoch 6/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.6716 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.6387 - acc: 0.5910
3000/9534 [========>.....................] - ETA: 0s - loss: 1.6163 - acc: 0.5910
4000/9534 [===========>..................] - ETA: 0s - loss: 1.6130 - acc: 0.5882
5000/9534 [==============>...............] - ETA: 0s - loss: 1.5982 - acc: 0.5890
6000/9534 [=================>............] - ETA: 0s - loss: 1.5861 - acc: 0.5892
7000/9534 [=====================>........] - ETA: 0s - loss: 1.5724 - acc: 0.5914
8000/9534 [========================>.....] - ETA: 0s - loss: 1.5578 - acc: 0.5922
9000/9534 [===========================>..] - ETA: 0s - loss: 1.5492 - acc: 0.5904
9534/9534 [==============================] - 0s - loss: 1.5468 - acc: 0.5893 - val_loss: 1.4677 - val_acc: 0.5585
Epoch 7/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.4380 - acc: 0.5790
2000/9534 [=====>........................] - ETA: 0s - loss: 1.4332 - acc: 0.5900
3000/9534 [========>.....................] - ETA: 0s - loss: 1.4208 - acc: 0.5957
4000/9534 [===========>..................] - ETA: 0s - loss: 1.4073 - acc: 0.5985
5000/9534 [==============>...............] - ETA: 0s - loss: 1.4027 - acc: 0.5960
6000/9534 [=================>............] - ETA: 0s - loss: 1.3922 - acc: 0.5950
7000/9534 [=====================>........] - ETA: 0s - loss: 1.3842 - acc: 0.5951
8000/9534 [========================>.....] - ETA: 0s - loss: 1.3729 - acc: 0.5988
9000/9534 [===========================>..] - ETA: 0s - loss: 1.3611 - acc: 0.6012
9534/9534 [==============================] - 1s - loss: 1.3588 - acc: 0.6015 - val_loss: 1.3387 - val_acc: 0.5717
Epoch 8/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.3429 - acc: 0.5750
2000/9534 [=====>........................] - ETA: 0s - loss: 1.3071 - acc: 0.5980
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2915 - acc: 0.6007
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2834 - acc: 0.5977
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2791 - acc: 0.6008
6000/9534 [=================>............] - ETA: 0s - loss: 1.2636 - acc: 0.6043
7000/9534 [=====================>........] - ETA: 0s - loss: 1.2521 - acc: 0.6049
8000/9534 [========================>.....] - ETA: 0s - loss: 1.2495 - acc: 0.6041
9000/9534 [===========================>..] - ETA: 0s - loss: 1.2506 - acc: 0.6031
9534/9534 [==============================] - 1s - loss: 1.2491 - acc: 0.6022 - val_loss: 1.2617 - val_acc: 0.5698
Epoch 9/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1627 - acc: 0.6240
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1709 - acc: 0.6235
3000/9534 [========>.....................] - ETA: 0s - loss: 1.2001 - acc: 0.6127
4000/9534 [===========>..................] - ETA: 0s - loss: 1.2000 - acc: 0.6098
5000/9534 [==============>...............] - ETA: 0s - loss: 1.2002 - acc: 0.6096
6000/9534 [=================>............] - ETA: 0s - loss: 1.1969 - acc: 0.6085
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1894 - acc: 0.6117
9534/9534 [==============================] - 1s - loss: 1.1793 - acc: 0.6094 - val_loss: 1.2151 - val_acc: 0.5679
Epoch 10/100
1000/9534 [==>...........................] - ETA: 1s - loss: 1.1436 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1369 - acc: 0.6260
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1366 - acc: 0.6207
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6210
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1276 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.1289 - acc: 0.6217
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1321 - acc: 0.6180
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1352 - acc: 0.6150
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1341 - acc: 0.6141
9534/9534 [==============================] - 0s - loss: 1.1349 - acc: 0.6129 - val_loss: 1.1946 - val_acc: 0.5632
Epoch 11/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.1684 - acc: 0.5930
2000/9534 [=====>........................] - ETA: 0s - loss: 1.1338 - acc: 0.6075
3000/9534 [========>.....................] - ETA: 0s - loss: 1.1177 - acc: 0.6140
4000/9534 [===========>..................] - ETA: 0s - loss: 1.1293 - acc: 0.6075
5000/9534 [==============>...............] - ETA: 0s - loss: 1.1235 - acc: 0.6154
6000/9534 [=================>............] - ETA: 0s - loss: 1.1188 - acc: 0.6173
7000/9534 [=====================>........] - ETA: 0s - loss: 1.1147 - acc: 0.6179
8000/9534 [========================>.....] - ETA: 0s - loss: 1.1068 - acc: 0.6196
9000/9534 [===========================>..] - ETA: 0s - loss: 1.1090 - acc: 0.6190
9534/9534 [==============================] - 0s - loss: 1.1092 - acc: 0.6177 - val_loss: 1.1788 - val_acc: 0.5689
Epoch 12/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0702 - acc: 0.6280
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0742 - acc: 0.6280
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0821 - acc: 0.6237
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0868 - acc: 0.6233
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0807 - acc: 0.6258
6000/9534 [=================>............] - ETA: 0s - loss: 1.0884 - acc: 0.6208
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0905 - acc: 0.6187
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0895 - acc: 0.6205
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0899 - acc: 0.6200
9534/9534 [==============================] - 1s - loss: 1.0900 - acc: 0.6205 - val_loss: 1.1598 - val_acc: 0.5830
Epoch 13/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0730 - acc: 0.6340
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0649 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0600 - acc: 0.6430
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0718 - acc: 0.6350
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0821 - acc: 0.6280
6000/9534 [=================>............] - ETA: 0s - loss: 1.0779 - acc: 0.6295
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0713 - acc: 0.6316
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0737 - acc: 0.6289
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0767 - acc: 0.6261
9534/9534 [==============================] - 1s - loss: 1.0752 - acc: 0.6259 - val_loss: 1.1589 - val_acc: 0.5642
Epoch 14/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0148 - acc: 0.6520
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0395 - acc: 0.6430
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0503 - acc: 0.6377
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0521 - acc: 0.6382
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0529 - acc: 0.6388
6000/9534 [=================>............] - ETA: 0s - loss: 1.0519 - acc: 0.6392
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0561 - acc: 0.6359
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0547 - acc: 0.6332
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0591 - acc: 0.6313
9534/9534 [==============================] - 0s - loss: 1.0606 - acc: 0.6301 - val_loss: 1.1577 - val_acc: 0.5774
Epoch 15/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0513 - acc: 0.6410
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0635 - acc: 0.6245
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0500 - acc: 0.6280
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0530 - acc: 0.6257
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0585 - acc: 0.6232
6000/9534 [=================>............] - ETA: 0s - loss: 1.0562 - acc: 0.6233
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0507 - acc: 0.6267
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0540 - acc: 0.6267
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0513 - acc: 0.6286
9534/9534 [==============================] - 0s - loss: 1.0492 - acc: 0.6290 - val_loss: 1.1608 - val_acc: 0.5802
Epoch 16/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0553 - acc: 0.6300
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0582 - acc: 0.6305
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0341 - acc: 0.6407
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0312 - acc: 0.6398
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0454 - acc: 0.6324
6000/9534 [=================>............] - ETA: 0s - loss: 1.0438 - acc: 0.6332
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0445 - acc: 0.6323
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0426 - acc: 0.6331
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0439 - acc: 0.6323
9534/9534 [==============================] - 0s - loss: 1.0427 - acc: 0.6323 - val_loss: 1.1544 - val_acc: 0.5764
Epoch 17/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0633 - acc: 0.6190
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0407 - acc: 0.6300
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0417 - acc: 0.6343
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0322 - acc: 0.6402
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0283 - acc: 0.6426
6000/9534 [=================>............] - ETA: 0s - loss: 1.0355 - acc: 0.6400
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0361 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0336 - acc: 0.6392
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0309 - acc: 0.6394
9534/9534 [==============================] - 0s - loss: 1.0342 - acc: 0.6382 - val_loss: 1.1575 - val_acc: 0.5755
Epoch 18/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0289 - acc: 0.6510
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0233 - acc: 0.6505
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0176 - acc: 0.6507
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0194 - acc: 0.6500
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0242 - acc: 0.6442
6000/9534 [=================>............] - ETA: 0s - loss: 1.0239 - acc: 0.6423
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0249 - acc: 0.6413
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0264 - acc: 0.6404
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0277 - acc: 0.6406
9534/9534 [==============================] - 0s - loss: 1.0299 - acc: 0.6389 - val_loss: 1.1597 - val_acc: 0.5708
Epoch 19/100
1000/9534 [==>...........................] - ETA: 0s - loss: 1.0271 - acc: 0.6420
2000/9534 [=====>........................] - ETA: 0s - loss: 1.0114 - acc: 0.6445
3000/9534 [========>.....................] - ETA: 0s - loss: 1.0046 - acc: 0.6510
4000/9534 [===========>..................] - ETA: 0s - loss: 1.0137 - acc: 0.6453
5000/9534 [==============>...............] - ETA: 0s - loss: 1.0074 - acc: 0.6492
6000/9534 [=================>............] - ETA: 0s - loss: 1.0112 - acc: 0.6490
7000/9534 [=====================>........] - ETA: 0s - loss: 1.0072 - acc: 0.6504
8000/9534 [========================>.....] - ETA: 0s - loss: 1.0093 - acc: 0.6496
9000/9534 [===========================>..] - ETA: 0s - loss: 1.0137 - acc: 0.6452
9534/9534 [==============================] - 0s - loss: 1.0159 - acc: 0.6451 - val_loss: 1.1603 - val_acc: 0.5651

Body:
cross validation code is as follows:

skf = KFold(n_splits=cross_validation, shuffle=True)
for train_index, test_index in skf.split(X):
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = Y[train_index], Y[test_index]
    model = None
    model = self.__create_model()
    model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(X_test, y_test))

X and Y are two matrix with shape (10000, 507) and (10000, 7)


问:
nodejs setinterval convert to real time
I am building small multiplayer game and iam having hard time to grasp setInterval configuration. Lets say that i want to give players abilities that will run on cooldown or spawn certain objects in actual time interval (like every 5 seconds or have 2 seconds cool down). The problem is that I cannot sync server setInterval loop with real time concept.

for example i have this loop that runs cooldowns:

```<code>setInterval(function() {
    game.mechanics.buffered.cooldowns.run();
}, 10);
</code>```

I have notices that if I lower this 10 value, cooldowns run faster, if i put it to higher number, they run slower, but i have no idea how to sync it for real time. I dont even know what value should be put there in server loop in the first place, i am happy with 10ms so far but real time cooldowns wont work with it currently.

Logic points that setTimeout would be more proper solution for spawning and such but setInterval gives me possibility of providing progress bar while setTimeout does not.

The question would be, how to properly configure this loop so then i can say in cooldown object that it lasts 2 seconds and it will be executed after those 2 seconds.

答:
It is not perfect solution, but it gets you started.</p>

```<code>var last = 0,
    current = 0,
    tick = 10,
    seconds = 3;

setInterval(function() {
    current += tick;
    if(current - last >= seconds * 1000) {
        last = current;
        console.log(new Date().getSeconds());
    }
}, tick);
</code>```

Title: nodejs setinterval convert to real time

Body:
I am building small multiplayer game and iam having hard time to grasp setInterval configuration. Lets say that i want to give players abilities that will run on cooldown or spawn certain objects in actual time interval (like every 5 seconds or have 2 seconds cool down). The problem is that I cannot sync server setInterval loop with real time concept.

for example i have this loop that runs cooldowns:

setInterval(function() {
    game.mechanics.buffered.cooldowns.run();
}, 10);

I have notices that if I lower this 10 value, cooldowns run faster, if i put it to higher number, they run slower, but i have no idea how to sync it for real time. I dont even know what value should be put there in server loop in the first place, i am happy with 10ms so far but real time cooldowns wont work with it currently.

Logic points that setTimeout would be more proper solution for spawning and such but setInterval gives me possibility of providing progress bar while setTimeout does not.

The question would be, how to properly configure this loop so then i can say in cooldown object that it lasts 2 seconds and it will be executed after those 2 seconds.

Body:
It is not perfect solution, but it gets you started.

var last = 0,
    current = 0,
    tick = 10,
    seconds = 3;

setInterval(function() {
    current += tick;
    if(current - last >= seconds * 1000) {
        last = current;
        console.log(new Date().getSeconds());
    }
}, tick);


问:
VBA Removing pivot subtotals from several sheets
I've been using below macro to remove subtotals on the active sheet. However, I was thinking that instead of using it 5 times (and having to select the sheet each time before using the macro) it could be adjusted to either Loop (probably not as there's 12 sheets with pivot tables and I'm only interested in 5) or use the Case to define the sheets with pivot tables I need modified.

Problem is I'm still quite new to VBA and couldn't manage to make it work so far. Any help would be greatly appreciated.

Base Code:

```<code>Sub NoSubtotals()

    Dim pt As PivotTable
    Dim pf As PivotField

    On Error Resume Next
    For Each pt In ActiveSheet.PivotTables
        For Each pf In pt.PivotFields
            pf.Subtotals(1) = True
            pf.Subtotals(1) = False
        Next pf
    Next pt
End Sub
</code>```

Sheets with Pivot Tables I want to remove subtotals from:

Header

Item_Breakdown

Settl_List

MatDef

All_Records

答:
Loop through the worksheets you want to use:</p>

```<code>Sub NoSubtotals()

    Dim pt As PivotTable
    Dim pf As PivotField
    Dim ws As Worksheet
    For Each ws In Worksheets(Array("Header", _
                                    "Item_Breakdown", _
                                    "Settl_List", _
                                    "MatDef", _
                                    "All_Records"))

        On Error Resume Next
        For Each pt In ws.PivotTables
            For Each pf In pt.PivotFields
                pf.Subtotals(1) = True
                pf.Subtotals(1) = False
            Next pf
        Next pt
        On Error GoTo 0
    Next
End Sub
</code>```

Body:
I've been using below macro to remove subtotals on the active sheet. However, I was thinking that instead of using it 5 times (and having to select the sheet each time before using the macro) it could be adjusted to either Loop (probably not as there's 12 sheets with pivot tables and I'm only interested in 5) or use the Case to define the sheets with pivot tables I need modified.

Problem is I'm still quite new to VBA and couldn't manage to make it work so far. Any help would be greatly appreciated.

Base Code:

Sub NoSubtotals()

    Dim pt As PivotTable
    Dim pf As PivotField

    On Error Resume Next
    For Each pt In ActiveSheet.PivotTables
        For Each pf In pt.PivotFields
            pf.Subtotals(1) = True
            pf.Subtotals(1) = False
        Next pf
    Next pt
End Sub

Sheets with Pivot Tables I want to remove subtotals from:

Header

Item_Breakdown

Settl_List

MatDef

All_Records

Body:
Loop through the worksheets you want to use:

Sub NoSubtotals()

    Dim pt As PivotTable
    Dim pf As PivotField
    Dim ws As Worksheet
    For Each ws In Worksheets(Array("Header", _
                                    "Item_Breakdown", _
                                    "Settl_List", _
                                    "MatDef", _
                                    "All_Records"))

        On Error Resume Next
        For Each pt In ws.PivotTables
            For Each pf In pt.PivotFields
                pf.Subtotals(1) = True
                pf.Subtotals(1) = False
            Next pf
        Next pt
        On Error GoTo 0
    Next
End Sub


答:
I propose to use this approach :

```<code>List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);

List<Integer> badNumbers = numbers.stream().filter(n -> n % 2 != 0).collect(Collectors.toList());
</code>```

In this case badNumbers will be empty if all elements satisfy n%2 = 0 otherwise it will contains values that doesn't.

Title: Find which element of the stream does not match the given predicate in allmatch

Body:
I propose to use this approach :

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);

List<Integer> badNumbers = numbers.stream().filter(n -> n % 2 != 0).collect(Collectors.toList());

In this case badNumbers will be empty if all elements satisfy n%2 = 0 otherwise it will contains values that doesn't.


问:
Help finding paths
```<code>% link(Origin,Destination,Speed,Length).
link(paris,milano,140,360).
link(paris,london,200,698).
link(berlin,atena,110,714).
link(atena,paris,90,370).
</code>```

I need to write this route predicate so I get a Path from city X to city Y.

```<code>route(Origin,Destination,TrainType,Path,Length,Duration).
</code>```

I am new to Prolog, so I wrote something like this. I know it's not correct:

```<code>route(Origin,Destination,TrainType,Path,Legth,Duration) :-
    link(Origin,City,Len),
    City \= Origin,
    NewLen is Length + Len,
    route(City,Destination,TrainType,Path,NewLen,Duration).
</code>```

答:
Your predicate lacks a base case, that tells it when to stop. Right now, your predicate will always call itself until it fails (or worse, loops indefinitely, depending on your link predicate). The following gives you a reverse path:

```<code>route(Goal, Goal, Path, Path).  % base case
route(From, To, Path0, Path) :-
    direct_link(From, Via),
    route(Via, To, [From|Path0], Path).
</code>```

where a direct link means you can get from A to B; I'm assuming railways are bidirectional:

```<code>direct_link(A,B) :- link(A, B, _Speed, _Length).
direct_link(B,A) :- link(B, A, _Speed, _Length).
</code>```

You will need to call reverse on the path and add arguments to keep track of length and duration. I'll leave that as an exercise.

Title: Help finding paths

Body:
% link(Origin,Destination,Speed,Length).
link(paris,milano,140,360).
link(paris,london,200,698).
link(berlin,atena,110,714).
link(atena,paris,90,370).

I need to write this route predicate so I get a Path from city X to city Y.

route(Origin,Destination,TrainType,Path,Length,Duration).

I am new to Prolog, so I wrote something like this. I know it's not correct:

route(Origin,Destination,TrainType,Path,Legth,Duration) :-
    link(Origin,City,Len),
    City \= Origin,
    NewLen is Length + Len,
    route(City,Destination,TrainType,Path,NewLen,Duration).

Body:
Your predicate lacks a base case, that tells it when to stop. Right now, your predicate will always call itself until it fails (or worse, loops indefinitely, depending on your link predicate). The following gives you a reverse path:

route(Goal, Goal, Path, Path).  % base case
route(From, To, Path0, Path) :-
    direct_link(From, Via),
    route(Via, To, [From|Path0], Path).

where a direct link means you can get from A to B; I'm assuming railways are bidirectional:

direct_link(A,B) :- link(A, B, _Speed, _Length).
direct_link(B,A) :- link(B, A, _Speed, _Length).

You will need to call reverse on the path and add arguments to keep track of length and duration. I'll leave that as an exercise.


问:
Send PHP particular variable to angualrjs controller
I have a PHP page with three echo statement. I want to get the particular $result variable in angularjs on success. I am using alert(data) to alert all the echo statement. How do I get the particular PHP variable in angularjs.

PHP:

```<code>      function add($value1,$value2)
      {
               $result =$value1 + $value2;
                echo("The sum of $value1 and $value2 is $result ");
                echo("$value1 + $value2 = $result");
                echo("$result");
                exit;
       }
</code>```

3 echo statements. I want the $result variable send to angularjs.

app.js :

```<code>            $scope.cal=function(){

   $scope.opers = $scope.oper ;
      $http({
                    method: "POST",
                   url: "oper.php",

                  data:{ 'value': $scope.value1,
                          'valu': $scope.value2,
                          'opers': $scope.oper,
                          } ,
             headers: {'Content-Type': 'application/json'}
      })

      .success(function(data) {

        console.log(data);
        alert(data);
        $scope.result = data ;

    } );
</code>```

答:
Simple but functional:

IN PHP: create a variable, example

```<code>$manualjson ="[{"value1":"'.$value1.'","value2":"'.$value2.'","value3":"'.$value3.'"}]";
echo $manualjson;
</code>```

then in app.js

```<code>var text = (returned $manualjson) --get your echo into a var

obj = JSON.parse(text);
var value1= obj[0].value1;
var value2= obj[0].value2;
var value3= obj[0].value3;
</code>```

A little bit rude but functional

ContentLicense: CC BY-SA 4.0

Body:
I have a PHP page with three echo statement. I want to get the particular $result variable in angularjs on success. I am using alert(data) to alert all the echo statement. How do I get the particular PHP variable in angularjs.

PHP:

      function add($value1,$value2)
      {
               $result =$value1 + $value2;
                echo("The sum of $value1 and $value2 is $result ");
                echo("$value1 + $value2 = $result");
                echo("$result");
                exit;
       }

3 echo statements. I want the $result variable send to angularjs.

app.js :

            $scope.cal=function(){

   $scope.opers = $scope.oper ;
      $http({
                    method: "POST",
                   url: "oper.php",

                  data:{ 'value': $scope.value1,
                          'valu': $scope.value2,
                          'opers': $scope.oper,
                          } ,
             headers: {'Content-Type': 'application/json'}
      })

      .success(function(data) {

        console.log(data);
        alert(data);
        $scope.result = data ;

    } );

Body:
Simple but functional:

IN PHP: create a variable, example

$manualjson ="[{"value1":"'.$value1.'","value2":"'.$value2.'","value3":"'.$value3.'"}]";
echo $manualjson;

then in app.js

var text = (returned $manualjson) --get your echo into a var

obj = JSON.parse(text);
var value1= obj[0].value1;
var value2= obj[0].value2;
var value3= obj[0].value3;

A little bit rude but functional


问:
replace column name with file name shell script
How to replace the 2nd column name in a .csv file with its corresponding file name for all files within a directory?
Does anyone know how to do this with shell scripting? sed or awk

input file name CDXV1.csv

```<code>Gene,RPKM(26558640 pairs)
ENSTGUG00000013338 (GAPDH),971.678203888
ENSTGUG00000005054 (CAMKV),687.81249397
ENSTGUG00000006651 (ARPP19),634.296191033
ENSTGUG00000002582 (ITM2A),613.756010638
</code>```

output file name CDXV1.csv (same)

```<code>Gene,CDXV1(26558640 pairs)
ENSTGUG00000013338 (GAPDH),971.678203888
ENSTGUG00000005054 (CAMKV),687.81249397
ENSTGUG00000006651 (ARPP19),634.296191033
ENSTGUG00000002582 (ITM2A),613.756010638
</code>```

答:
sed solution:

```<code>for f in yourdir/*.csv; do sed -i "1s~^\([^,]*\),\([^(]*\)~\1,${f%%.*}~g" "$f"; done
</code>```

Details:

for f in yourdir/*.csv - iterating through csv filenames

-i - modify the file in-place

1s - perform substitution only on the 1st line

~ - used as sed subcommand sections separator

^\([^,]*\),\([^(]*\) - capturing the 1st field and 2nd field value (till encountering ()

${f%%.*} - bash variable substitution, truncate right of the first .

Body:
How to replace the 2nd column name in a .csv file with its corresponding file name for all files within a directory?
Does anyone know how to do this with shell scripting? sed or awk

input file name CDXV1.csv

Gene,RPKM(26558640 pairs)
ENSTGUG00000013338 (GAPDH),971.678203888
ENSTGUG00000005054 (CAMKV),687.81249397
ENSTGUG00000006651 (ARPP19),634.296191033
ENSTGUG00000002582 (ITM2A),613.756010638

output file name CDXV1.csv (same)

Gene,CDXV1(26558640 pairs)
ENSTGUG00000013338 (GAPDH),971.678203888
ENSTGUG00000005054 (CAMKV),687.81249397
ENSTGUG00000006651 (ARPP19),634.296191033
ENSTGUG00000002582 (ITM2A),613.756010638

Body:
sed solution:

for f in yourdir/*.csv; do sed -i "1s~^\([^,]*\),\([^(]*\)~\1,${f%%.*}~g" "$f"; done

Details:

for f in yourdir/*.csv - iterating through csv filenames

-i - modify the file in-place

1s - perform substitution only on the 1st line

~ - used as sed subcommand sections separator

^\([^,]*\),\([^(]*\) - capturing the 1st field and 2nd field value (till encountering ()

${f%%.*} - bash variable substitution, truncate right of the first .


问:
Docker compose can not create container for postgresql and redis
I have a problem with docker-compose and can not create containers for service postgresql and redis, after I run docker-compose up -d I've got this error:

```<code>ERROR: for dockerizingdjango_postgres_1  Cannot create container for service postgres: b'invalid port specification: "None"'
Creating dockerizingdjango_redis_1 ...
Creating dockerizingdjango_redis_1 ... error
ERROR: for dockerizingdjango_redis_1  Cannot create container for service redis: b'invalid port specification: "None"'
ERROR: for postgres  Cannot create container for service postgres: b'invalid port specification: "None"'
ERROR: for redis  Cannot create container for service redis: b'invalid port specification: "None"'
ERROR: Encountered errors while bringing up the project.
</code>```

The docker-compose.yml file looks like this:

```<code>web:
  restart: always
  build: ./web
  expose:
    - "8000"
  links:
    - postgres:postgres
    - redis:redis
  volumes:
    - /usr/src/app
    - /usr/src/app/static
  env_file: .env
  environment:
    DEBUG: 'true'
  command: /usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000

apache:
  restart: always
  build: ./apache/
  ports:
    - "80:80"
  volumes:
    - /www/static
    - /www/media
  volumes_from:
    - web
  links:
    - web:web

postgres:
  restart: always
  image: postgres:latest
  ports:
    - "5432:5432"
  volumes:
    - pgdata:/var/lib/postgresql/data/

redis:
  restart: always
  image: redis:latest
  ports:
    - "6379:6379"
  volumes:
    - redisdata:/data
</code>```

I'm using this version of docker-compose:

```<code>docker-compose version 1.13.0, build 1719ceb
docker-py version: 2.3.0
CPython version: 3.4.3
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
</code>```

also I'm using python3.5 for this container, because I'm serving django in this container, so can someone help me and explain what is going on here, and how to solve this, thanks.

答: It seems that you are hitting this issue(https://github.com/docker/compose/issues/4729). Workaround as mentioned in link is to downgrade compose or upgrade python.</p>

Body:
I have a problem with docker-compose and can not create containers for service postgresql and redis, after I run docker-compose up -d I've got this error:

ERROR: for dockerizingdjango_postgres_1  Cannot create container for service postgres: b'invalid port specification: "None"'
Creating dockerizingdjango_redis_1 ...
Creating dockerizingdjango_redis_1 ... error
ERROR: for dockerizingdjango_redis_1  Cannot create container for service redis: b'invalid port specification: "None"'
ERROR: for postgres  Cannot create container for service postgres: b'invalid port specification: "None"'
ERROR: for redis  Cannot create container for service redis: b'invalid port specification: "None"'
ERROR: Encountered errors while bringing up the project.

The docker-compose.yml file looks like this:

web:
  restart: always
  build: ./web
  expose:
    - "8000"
  links:
    - postgres:postgres
    - redis:redis
  volumes:
    - /usr/src/app
    - /usr/src/app/static
  env_file: .env
  environment:
    DEBUG: 'true'
  command: /usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000

apache:
  restart: always
  build: ./apache/
  ports:
    - "80:80"
  volumes:
    - /www/static
    - /www/media
  volumes_from:
    - web
  links:
    - web:web

postgres:
  restart: always
  image: postgres:latest
  ports:
    - "5432:5432"
  volumes:
    - pgdata:/var/lib/postgresql/data/

redis:
  restart: always
  image: redis:latest
  ports:
    - "6379:6379"
  volumes:
    - redisdata:/data

I'm using this version of docker-compose:

docker-compose version 1.13.0, build 1719ceb
docker-py version: 2.3.0
CPython version: 3.4.3
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014

also I'm using python3.5 for this container, because I'm serving django in this container, so can someone help me and explain what is going on here, and how to solve this, thanks.


问:
I'm getting a "Cannot find entry file index.android.js" error after upgrading to react-native 0.45 using react-native-git-upgrade
Before the upgrade I was using react-native 0.42 and everything worked. I even tried running a new project and still the same error. How do I fix this? Should I revert back to the older version?

React Native App Error

答:
that's how i've solved the issue in my Windows PC:

in the first admin's cmd.exe typed:

```<code>netstat -a -b -o
</code>```

Found PID of 8081 server.
Then i killed this proccess by typing

```<code>taskkill /pid 1234
</code>```

where '1234' is your PID found before.
open normal cmd.exe and typed:

```<code>react-native start
</code>```

open another normal cmd.exe and typed:

```<code>react-native run-android
</code>```

Body:
that's how i've solved the issue in my Windows PC:

in the first admin's cmd.exe typed:

netstat -a -b -o

Found PID of 8081 server.
Then i killed this proccess by typing

taskkill /pid 1234

where '1234' is your PID found before.
open normal cmd.exe and typed:

react-native start

open another normal cmd.exe and typed:

react-native run-android


问:
Writing a function for smoothing center values in specified range
I'm not sure this is the right place to ask this kind of question (maybe mathematica would be better ?).

I'm writing a program that reads input values from an analog joystick.

The values range from -100 to 100 with 0 being the center value.

My problem is, the stick values aren't very precise in the center area. For example, with the stick released, I should get an input value equal to 0 but I often get values like 2, 7, -5, etc (almost never exceeding 10 or -10).

What I'd like to do is applying a "smoothing" function to reduce the values around the 0 area.

I'm not experienced with mathematics and the best function I could find so far is:

```<code>function smooth(x)  {
    return Math.pow(x,3)/10000;
}
</code>```

This gives me this kind of values:

As you can see, this function is too "aggressive" because even f(20) ~= 0 !

Any idea of which better function I could use ?

答:
I ended up mixing my first solution with the one provided by Nina.

```<code>var deadzone = 15;

function smooth(x) {
    return Math.abs(x) <= deadzone ? Math.pow(x,3)/Math.pow(deadzone,2) : x;
}
</code>```

See this graph

Body:
I'm not sure this is the right place to ask this kind of question (maybe mathematica would be better ?).

I'm writing a program that reads input values from an analog joystick.

The values range from -100 to 100 with 0 being the center value.

My problem is, the stick values aren't very precise in the center area. For example, with the stick released, I should get an input value equal to 0 but I often get values like 2, 7, -5, etc (almost never exceeding 10 or -10).

What I'd like to do is applying a "smoothing" function to reduce the values around the 0 area.

I'm not experienced with mathematics and the best function I could find so far is:

function smooth(x)  {
    return Math.pow(x,3)/10000;
}

This gives me this kind of values:

As you can see, this function is too "aggressive" because even f(20) ~= 0 !

Any idea of which better function I could use ?

Body:
I ended up mixing my first solution with the one provided by Nina.

var deadzone = 15;

function smooth(x) {
    return Math.abs(x) <= deadzone ? Math.pow(x,3)/Math.pow(deadzone,2) : x;
}

See this graph


问:
Executing multiple cassandra scripts on same keyspace
To execute a single cassandra sript through cqlsh, I am executing the below script and it is working just fine  :

```<code>cqlsh -k mykeyspace -u username -p password  -f file1.cql
</code>```

But , I have multiple cqlfiles , So I created a master cql file with entries like

```<code>master.cql
 --Content
source file1.cql
source files.cql
source file3.cql
</code>```

When executing the above script :

```<code>cqlsh -k mykeyspace -u username -p password  -f master.cql
</code>```

I am getting an error message like  "No Keyspace has been specified".
I don't want to hardcode the keyspace in the individual cql file. What is the way to execute multiple cql files at once ?

答:
-f  switch allows only single file as of cassandra 3.0.

To run multiple files using cql shell you can create a shell file in linux and execute it.

Example:

You can create a shell file below and run it.

```<code>cqlsh -k mykeyspace -u username -p password  -f file1.cql
cqlsh -k mykeyspace -u username -p password  -f file2.cql
cqlsh -k mykeyspace -u username -p password  -f file3.cql
</code>```

so instead of master.cql master.sh with above commands should do the trick.

Body:
To execute a single cassandra sript through cqlsh, I am executing the below script and it is working just fine  :

cqlsh -k mykeyspace -u username -p password  -f file1.cql

But , I have multiple cqlfiles , So I created a master cql file with entries like

master.cql
 --Content
source file1.cql
source files.cql
source file3.cql

When executing the above script :

cqlsh -k mykeyspace -u username -p password  -f master.cql

I am getting an error message like  "No Keyspace has been specified".
I don't want to hardcode the keyspace in the individual cql file. What is the way to execute multiple cql files at once ?

Body:
-f  switch allows only single file as of cassandra 3.0.

To run multiple files using cql shell you can create a shell file in linux and execute it.

Example:

You can create a shell file below and run it.

cqlsh -k mykeyspace -u username -p password  -f file1.cql
cqlsh -k mykeyspace -u username -p password  -f file2.cql
cqlsh -k mykeyspace -u username -p password  -f file3.cql

so instead of master.cql master.sh with above commands should do the trick.


问:
Error H10: Application Error on Heroku
I am new on working with Rails and Heroku. I tried pushing my app onto Heroku and the push was successful but for some reason I receive an application error on my Heroku Site:

```<code>"An error occurred in the application and your page could not be served."
</code>```

Would be great if someone could help. Passing along some information about my app and the environment.

In my Gem file I have the following databases running:

```<code>group :development, :test do
gem "sqlite3", "~> 1.3.6"
end

group :production do
gem 'pg'
end

group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
</code>```

In the Database.yml the following databases are setup:

```<code>development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
</code>```

To begin with I don't understand why the .yml file still shows Sqlite3 in the production server? Shouldn't it change to pgres. In the Heroku Logs this is the key error message that displays:

```<code> 2012-10-23T19:22:36+00:00 heroku[router]: Error H10 (App crashed) -> GET thawing-dusk-  8202.herokuapp.com/analysis dyno= queue= wait= service= status=503 bytes=
</code>```

Hope someone can help me out with this!

Thanks,

答:
Your Rails application is most likely raising an exception upon startup from your source files.

This exception may not be obvious in the development environment because Rails doesn't eagerly load files in development or testing. However, when the production environment causes the Rails application to eagerly load all of the source files, the exception interrupts the application startup process and the application crashes with a lacking stack trace on the Heroku logs.

To come upon an informative stack trace, access the Rails console from your terminal running heroku run rails c, assuming you have the Heroku Toolbelt included and configured with your project. This will also fail on startup, as you are accessing the production environment, but the stack trace will be more extensive than the Heroku logs.

An alternative approach to diagnosing the problem would be to set the development environment to eager load source files.

```<code># config/environments/development.rb
Rails.application.configure do

  config.eager_load = true

end
</code>```

Finally, the best solution to this problem would be to review your test suite, if any, to include test cases that verify the source file's functionality.

Title: Error H10: Application Error on Heroku

Body:
I am new on working with Rails and Heroku. I tried pushing my app onto Heroku and the push was successful but for some reason I receive an application error on my Heroku Site:

"An error occurred in the application and your page could not be served."

Would be great if someone could help. Passing along some information about my app and the environment.

In my Gem file I have the following databases running:

group :development, :test do
gem "sqlite3", "~> 1.3.6"
end

group :production do
gem 'pg'
end

group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end

In the Database.yml the following databases are setup:

development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

To begin with I don't understand why the .yml file still shows Sqlite3 in the production server? Shouldn't it change to pgres. In the Heroku Logs this is the key error message that displays:

 2012-10-23T19:22:36+00:00 heroku[router]: Error H10 (App crashed) -> GET thawing-dusk-  8202.herokuapp.com/analysis dyno= queue= wait= service= status=503 bytes=

Hope someone can help me out with this!

Thanks,

Body:
Your Rails application is most likely raising an exception upon startup from your source files.

This exception may not be obvious in the development environment because Rails doesn't eagerly load files in development or testing. However, when the production environment causes the Rails application to eagerly load all of the source files, the exception interrupts the application startup process and the application crashes with a lacking stack trace on the Heroku logs.

To come upon an informative stack trace, access the Rails console from your terminal running heroku run rails c, assuming you have the Heroku Toolbelt included and configured with your project. This will also fail on startup, as you are accessing the production environment, but the stack trace will be more extensive than the Heroku logs.

An alternative approach to diagnosing the problem would be to set the development environment to eager load source files.

# config/environments/development.rb
Rails.application.configure do

  config.eager_load = true

end

Finally, the best solution to this problem would be to review your test suite, if any, to include test cases that verify the source file's functionality.


问:
How to take Null values query expression using servlet and jsp
I need to calculate and retrieve data from SQL server database table in my table having the NoOfErrors and NoOfAudited columns.

I need to calculate the Accuracy based on these columns.

I have a query like this

```<code>select
   a.id,
   (100-((a.NoOfErrors*100)/ NULLIF(a.NoOfAudited,0))) as Accuracy
from Table1 a
 join Table2 pd
   on a.batchid=pd.id
where
  a.charge='"+Poster+"' and status=1
</code>```

The above query is executed only when the NoOfErrors and NoOfAudited columns contain some values.

I have all the values but if a value in any one of theNoOfErrors and NoOfAudited columns contains Null value it doesn't retrieve any data, and it shows No data found.

ResultSet data is not accepting null values

How can I make the query accept null values and retrieve data by replacing null to empty in jsp table?

答:
This line is problematic and should be corrected.

```<code>   (100-((a.NoOfErrors*100)/ NULLIF(a.NoOfAudited,0))) as Accuracy
</code>```

problem #1:

```<code>NULLIF(a.NoOfAudited,0)
</code>```

if NoOfAudited is NULL then the expression will return 0; basically you are dividing by zero. This should be replaced with 1 like below

```<code>NULLIF(a.NoOfAudited,1)
</code>```

problem #2

No checks for NULL value for NoOfErrors column.
In SQL server most NULL arithmetic results in NULL.
For example all below queries will yield NULL

```<code>select 100-NULL*100/0
select NULL*100
select NULL/0
select 100-NULL
</code>```

Therefore you'll get NULL value as Accuracy whenever NoOfErrors is NULL

To correct this part, you should write your query expression like

```<code>   (100-((COALESCE(a.NoOfErrors,0)*100)/ COALESCE(a.NoOfAudited,1))) as Accuracy
</code>```

Note that I've replaced NULLIF with COALESCE which is ANSI compliant and will run on both SQL server and MySQL

TLDR;

your query should be like

```<code>select
   a.id,
  case
   when COALESCE(a.NoOfErrors,a.NoOfAudited,'') =''
   then''
   else
    CAST((100-((COALESCE(a.NoOfErrors,0)*100)/ COALESCE(a.NoOfAudited,1))) as VARCHAR(10))as Accuracy
 end
from Table1 a
 join Table2 pd
   on a.batchid=pd.id
where
  a.charge='"+Poster+"' and status=1
</code>```

Body:
I need to calculate and retrieve data from SQL server database table in my table having the NoOfErrors and NoOfAudited columns.

I need to calculate the Accuracy based on these columns.

I have a query like this

select
   a.id,
   (100-((a.NoOfErrors*100)/ NULLIF(a.NoOfAudited,0))) as Accuracy
from Table1 a
 join Table2 pd
   on a.batchid=pd.id
where
  a.charge='"+Poster+"' and status=1

The above query is executed only when the NoOfErrors and NoOfAudited columns contain some values.

I have all the values but if a value in any one of theNoOfErrors and NoOfAudited columns contains Null value it doesn't retrieve any data, and it shows No data found.

ResultSet data is not accepting null values

How can I make the query accept null values and retrieve data by replacing null to empty in jsp table?

Body:
This line is problematic and should be corrected.

   (100-((a.NoOfErrors*100)/ NULLIF(a.NoOfAudited,0))) as Accuracy

problem #1:

NULLIF(a.NoOfAudited,0)

if NoOfAudited is NULL then the expression will return 0; basically you are dividing by zero. This should be replaced with 1 like below

NULLIF(a.NoOfAudited,1)

problem #2

No checks for NULL value for NoOfErrors column.
In SQL server most NULL arithmetic results in NULL.
For example all below queries will yield NULL

select 100-NULL*100/0
select NULL*100
select NULL/0
select 100-NULL

Therefore you'll get NULL value as Accuracy whenever NoOfErrors is NULL

To correct this part, you should write your query expression like

   (100-((COALESCE(a.NoOfErrors,0)*100)/ COALESCE(a.NoOfAudited,1))) as Accuracy

Note that I've replaced NULLIF with COALESCE which is ANSI compliant and will run on both SQL server and MySQL

TLDR;

your query should be like

select
   a.id,
  case
   when COALESCE(a.NoOfErrors,a.NoOfAudited,'') =''
   then''
   else
    CAST((100-((COALESCE(a.NoOfErrors,0)*100)/ COALESCE(a.NoOfAudited,1))) as VARCHAR(10))as Accuracy
 end
from Table1 a
 join Table2 pd
   on a.batchid=pd.id
where
  a.charge='"+Poster+"' and status=1


问:
Continuous Delivery with VSTS and Jenkins
I'm trying to get continuous delivery going with Jenkins (building, deploying) and VSTS (source control).  This is the desired workflow:

a developer branches off master, makes changes, creates a pull request

another developer reviews the PR and eventually merges it into master

some system (Jenkins or VSTS) detects that a PR was merged into master and...

increments a version number stored in a file within the repo

commits the version change back to master

builds

deploys

I was using Service Hooks within VSTS to detect the merge to master and execute a Jenkins task.  VSTS has 3 hooks I can use:

Build completed

Code pushed

Pull request merge commit created

I was under the impression that the third option would only occur when a PR was merged, but that's not the case.  Any additional commits to the branch, while it's associated with the PR triggers the hook.  This causes a bunch of unnecessary deployments.

I figured I could make Jenkins detect changes within VSTS.  There's a "Poll SCM" option, which takes a cron-like schedule.  The utterly confusing thing is, it doesn't appear that I can configure what exactly will be polled every X minutes (which repo, which branch).

What are my options here to trigger Jenkins tasks only when a PR is merged to master?  I would use the VSTS "Code pushed" Service Hook, but it goes into an infinite loop because Jenkins pushes to master when it increments the version.

答:
Refer to these steps below:

Create a new build definition for master

Select Triggers and enable Continuous Integration

Set the Branch Filters and Path filters (exclude the version number file that need to be changed)

Add task to modify version number file (e.g. PowerShell)

Add Command Line task (Tool: git; Arguments: config --global user.email “test@example.com”; Working folder: $(build.sourcesdirectory))

Add Command Line task (Tool: git; Arguments: config --global user.name "Your Name"; Working folder: $(build.sourcesdirectory))

Add Command Line task (Tool: git; Arguments: add [the modified file]; Working folder: $(build.sourcesdirectory))

Add Command Line task (Tool: git; Arguments: commit -m “update version”; Working folder: $(build.sourcesdirectory))

Add Command Line task (Tool:git; Arguments: push origin HEAD:$(Build.SourceBranchName) ”; Working folder: $(build.sourcesdirectory))

Add Jenkins Queue Job task to trigger Jenkins job


问:
Access Env variables within php
How to access environment variables located in  ~/.bash_profile from within PHP running with apache localhost (Mac)? I tried getenv() but no luck. Is there anything I need to change with php.ini?</p>

答:
Example from the PHP website:</p>

```<code><?php
    // Example use of getenv()
    $ip = getenv('REMOTE_ADDR');

    // Or simply use a Superglobal ($_SERVER or $_ENV)
    $ip = $_SERVER['REMOTE_ADDR'];

    // Safely get the value of an environment variable, ignoring whether
    // or not it was set by a SAPI or has been changed with putenv
    $ip = getenv('REMOTE_ADDR', true) ?: getenv('REMOTE_ADDR')
?>
</code>```

Title: Access Env variables within php

Body:
Example from the PHP website:

<?php
    // Example use of getenv()
    $ip = getenv('REMOTE_ADDR');

    // Or simply use a Superglobal ($_SERVER or $_ENV)
    $ip = $_SERVER['REMOTE_ADDR'];

    // Safely get the value of an environment variable, ignoring whether
    // or not it was set by a SAPI or has been changed with putenv
    $ip = getenv('REMOTE_ADDR', true) ?: getenv('REMOTE_ADDR')
?>


问:
syntax error, unexpected tIDENTIFIER, expecting keyword_end
What am I doing wrong?  I think all my ends are right.  I am getting this error for

```<code>describe "visiting the edit page" do

describe "submitting to the update action" do

describe "visiting the user index" do

describe "as wrong user" do

FactoryGirl.create(:user, email: "wrong@example.com")}
</code>```

and

```<code>describe "visiting Users#edit page" do
</code>```

This is the error I am getting when I run rspec

```<code>syntax error, unexpected tIDENTIFIER, expecting keyword_end

describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) {FactoryGirl.create(:user)}

      describe "when attempting to visit a protected page" do
        before do
          visit edit_user_path(user)
          fill_in "Email", with: user.email
          fill_in "Password", with: user.password
          click_button "Sign in"
        end

        describe "after signing in" do
          it "should render the desired protected page" do
            page.should have_selector('title', text: 'Edit user')
          end

          describe "when signing in again" do
            before do
              click_link "Sign out"
              click_link "Sign in"
              fill_in "Email", with: user.email
              fill_in "Password", with: user.password
              click_button "Sign in"
            end

            it "should render the default (profile) do
            page.should have_selector('title', text: user.name)
            end
          end
        end
      end

      describe "in the Users controller" do

        describe "visiting the edit page" do
          before {visit edit_user_path(user)}
          it { should have_selector('title', text: 'Sign in') }
          it {should have_selector('div.alert.alert-notice')}
        end

        describe "submitting to the update action" do
          before { put user_path(user)}
          specify {response.should redirect_to(signin_path)}
        end

        describe "visiting the user index" do
          before {visit users_path}
          it {should have_selector{'title', text: 'Sign in'}}
        end
      end
    end

    describe "as wrong user" do
      let(:user) {FactoryGirl.create(:user)}
      let(:wrong_user) {FactoryGirl.create(:user, email: "wrong@example.com")}
      before { sign_in user}

      describe "visiting Users#edit page" do
        before {visit edit_user_path(wrong_user)}
        it {should_not have_selector('title', text: 'Edit user')}
      end

      describe "submitting a PUT request to the Users#update action" do
        before {put user_path(wrong_user)}
        specify {response.should redirect_to(root_path)}
      end
    end
  end
end
</code>```

答: I had in the podspec this character ” instead of this ".</p>

Body:
What am I doing wrong?  I think all my ends are right.  I am getting this error for

describe "visiting the edit page" do

describe "submitting to the update action" do

describe "visiting the user index" do

describe "as wrong user" do

FactoryGirl.create(:user, email: "wrong@example.com")}

and

describe "visiting Users#edit page" do

This is the error I am getting when I run rspec

syntax error, unexpected tIDENTIFIER, expecting keyword_end

describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) {FactoryGirl.create(:user)}

      describe "when attempting to visit a protected page" do
        before do
          visit edit_user_path(user)
          fill_in "Email", with: user.email
          fill_in "Password", with: user.password
          click_button "Sign in"
        end

        describe "after signing in" do
          it "should render the desired protected page" do
            page.should have_selector('title', text: 'Edit user')
          end

          describe "when signing in again" do
            before do
              click_link "Sign out"
              click_link "Sign in"
              fill_in "Email", with: user.email
              fill_in "Password", with: user.password
              click_button "Sign in"
            end

            it "should render the default (profile) do
            page.should have_selector('title', text: user.name)
            end
          end
        end
      end

      describe "in the Users controller" do

        describe "visiting the edit page" do
          before {visit edit_user_path(user)}
          it { should have_selector('title', text: 'Sign in') }
          it {should have_selector('div.alert.alert-notice')}
        end

        describe "submitting to the update action" do
          before { put user_path(user)}
          specify {response.should redirect_to(signin_path)}
        end

        describe "visiting the user index" do
          before {visit users_path}
          it {should have_selector{'title', text: 'Sign in'}}
        end
      end
    end

    describe "as wrong user" do
      let(:user) {FactoryGirl.create(:user)}
      let(:wrong_user) {FactoryGirl.create(:user, email: "wrong@example.com")}
      before { sign_in user}

      describe "visiting Users#edit page" do
        before {visit edit_user_path(wrong_user)}
        it {should_not have_selector('title', text: 'Edit user')}
      end

      describe "submitting a PUT request to the Users#update action" do
        before {put user_path(wrong_user)}
        specify {response.should redirect_to(root_path)}
      end
    end
  end
end


问:
PHP, adding time to date();?
I have used this to get the server date,

```<code>$yd = getdate();

echo $yd['year'];
echo $yd['mon'];
echo $yd['mday'];
</code>```

...but how do I add something to it. For example, I want to know what date it will be in 7 days.

Thanks!

答: Use strtotime()

Title: PHP, adding time to date();?

Body:
I have used this to get the server date,

$yd = getdate();

echo $yd['year'];
echo $yd['mon'];
echo $yd['mday'];

...but how do I add something to it. For example, I want to know what date it will be in 7 days.

Thanks!

Body: Use strtotime()