GVKun编程网logo

model.evaluate()对于同一度量返回不同的值,具体取决于是以损失还是度量形式返回

1

本文将为您提供关于model.evaluate的详细介绍,我们还将为您解释对于同一度量返回不同的值,具体取决于是以损失还是度量形式返回的相关知识,同时,我们还将为您提供关于C输出不符合预期-全局变量返

本文将为您提供关于model.evaluate的详细介绍,我们还将为您解释对于同一度量返回不同的值,具体取决于是以损失还是度量形式返回的相关知识,同时,我们还将为您提供关于C 输出不符合预期 - 全局变量返回不同的值、Dart / Flutter按位移位运算符返回不同的值、equal()和equalsIgnoreCase()对于相等的字符串返回false、Excel-单元格包含列表中的值-返回列表值,但避免返回不正确的值的实用信息。

本文目录一览:

model.evaluate()对于同一度量返回不同的值,具体取决于是以损失还是度量形式返回

model.evaluate()对于同一度量返回不同的值,具体取决于是以损失还是度量形式返回

如果您使用与损耗和度量相同的功能,通常由于floating point precision errors而导致的结果会有细微的差别。

请参阅此SO Answer,其中对此情况进行了详细说明。

C 输出不符合预期 - 全局变量返回不同的值

C 输出不符合预期 - 全局变量返回不同的值

如何解决C 输出不符合预期 - 全局变量返回不同的值?

我正在尝试从文件中读取并将某种字数作为 occ_table 加载到二维数组中,该数组被声明为全局变量。我写了一个 OCC_print 函数来打印该数组中的结果。

但是代码的行为不像我预期的那样。在 readbychunks() 函数中, occ_prints 正确打印该二维数组的每次迭代。但是当我在 main 中做最后的打印时,第一列的数字是不同的。

对于代码凌乱,我深表歉意,下面附上代码test.c和要阅读的文件test.bwt

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int BUFFER_SIZE =30;
int c_SIZE = 96;
int c[96];
int GAP = 5;
int occ_height = 1;
int cLen =0;
int sLen = 0;
int** occ_table;

// max len of c list is 96 : ASCII 10 + 32-126 as given
//inputs a char ASCII # outputs i location in c[96]
int c_charEncoder(int ascii){
    if(ascii == 10){return 0;}
    else{ return ascii-32-1; }
}
int c_charDecoder(int c_location){
    if(c_location==0){return 10;}
    else{return c_location+32+1;}
}
//initiate occ table with allocated memories and initial values
void initiate_occ(){
    for (int i = 0; i< c_SIZE+1; i++)
    {
        occ_table[i] = (int*)malloc(sizeof(int)*(occ_height+1));
        for(int j = 0; j <= occ_height+1; j++){occ_table[i][j] = 0;}
    }
    // return occ_table;
}

//print OCC
void print_OCC(){
    //printf("OCC to be loaded \n\n");
    for ( int r = 0; r <occ_height; r++)
    {
        for (int i = 0; i < c_SIZE; i++)
        {   
            printf("%d ",occ_table[i][r]);
        }
        printf("\n");
    }  
}
void readbychunks(){
    int ctr = 0; // count how many chars in file read - if ctr -1 = row number
    FILE *fp = fopen("test.bwt","r");
    if (fp != NULL) {
        /* Go to the end of the file. */
        if (fseek(fp,0L,SEEK_END) == 0) {
            /* Get the size of the file. */
            sLen = ftell(fp);

            /* Allocate our buffer to that size. */
            char* source = malloc(sizeof(char) * (sLen/BUFFER_SIZE + 1));
            int occ_accumulator[96];
            for(int o=0;o<c_SIZE; o++){occ_accumulator[o]=0;}

            occ_height = sLen/GAP+1;
            initiate_occ();
            print_OCC();
            printf("occ height is %d length is %d \n\n",occ_height,c_SIZE);
            /* Go back to the start of the file. */
            fseek(fp,SEEK_SET);

            /* Read the entire file into memory by chunks */
            for(int i=0; i<sLen/BUFFER_SIZE+1;i++){
                int blockLen = fread(source,sizeof(char),BUFFER_SIZE,fp);
                
                for (int j = 0; j < blockLen; j++)
                {   
                    ctr ++;
                    char token= source[j];
                    int c_location = c_charEncoder(token);
                        printf("Token is %c \n C updated to:\n",token);
                    // increase c by 1
                    c[c_location]++;
                        // for (int x = 0; x < c_SIZE; x++){printf("%d ",c[x]);}
                    // increase occ_accumulator by 1
                        // printf("\nOCC new row is :\n");
                    occ_accumulator[c_location]++;
                        // for (int x = 0; x < c_SIZE; x++){printf("%d ",occ_accumulator[x]);}
                    // only push to occ_table with GAPs
                    if ((ctr-1)%GAP == 0){
                        int row = (ctr-1)/GAP;
                        printf("%d row current ctr is %d\n",row,ctr-1);
                            // for (int x = 0; x < c_SIZE; x++){printf("%d ",occ_accumulator[x]);}
                            // printf("\n");


                        for(int c=0; c<c_SIZE; c++){occ_table[c][row] = occ_accumulator[c];}
                            // for (int x = 0; x < c_SIZE; x++){printf(" accum table has %d,occ has %d\n ",occ_accumulator[x],occ_table[x][row]);}

                            print_OCC();
                            printf("\n");
                    }
                        // printf("%c has ascii %d should be in %d in c has decoded ASCII %d\n",source[j],c_charEncoder(source[j]),c_charDecoder(c_charEncoder(source[j])));

                }
            printf("%s",source);  
            memset(source,''\0'',BUFFER_SIZE); // reset the buffer
            }
        
  
            //free(source);
            fclose(fp);
            printf("\n");
        }
    }
}


int main(int argc,char const *argv[])
{
    occ_table = (int**)malloc(c_SIZE*sizeof(int*));
    readbychunks();
    printf("final OCC table is :\n");
    print_OCC();
    // printf("\n\n\n%d",occ_table[0][0]);
}

代码读取这个文件 test.bwt:

ipssm
pissii

我得到的结果:

as you can see two tables printed should be the same,but the final one has column 1 all 0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Dart / Flutter按位移位运算符返回不同的值

Dart / Flutter按位移位运算符返回不同的值

Dart将整数存储为带符号的64位值,从而为整数提供了−(2^63)2^63 − 1的范围。如果超过整数的最大值,则会发生回绕,并且最高有效位会丢失。

但是,使用兼容的JavaScript的按位运算符truncate their operands to 32-bit integers。这意味着您所看到的折回值(4294967296)比台式机或移动设备低得多。这就是为什么您的数字计算方式不同的原因。

docs for int的注释对此进行了说明。

,

要扩展斯蒂芬的答案(解决问题的原因),一种解决方案是使用标准数学运算符,因为这些运算符不会被截断为32位:

var checksum = 1150946793;
var shift = checksum * pow(2,5).toInt();
print(shift);

我敢肯定,这比使用按位运算要慢几个数量级,因此仅在绝对需要处理64位值的情况下才使用它可能是明智的选择(例如,以我的µs精度时间戳为例)。 / p>

equal()和equalsIgnoreCase()对于相等的字符串返回false

equal()和equalsIgnoreCase()对于相等的字符串返回false

我正在Mac上使用Eclipse IDE(版本:3.4.2),但遇到了以下问题。

使用equal()或equalsIgnoreCase()方法在字符串之间进行比较时,即使字符串相等,我也会收到false。例如,即使values [0]
=“ debug_mode”,以下代码也将以下条件视为false:

if (values[0].equalsIgnoreCase("debug_mode"))     debug_mode = true;

这是以下循环的一部分:

String value = dis.readLine();String values[] = value.trim().split("=");if (values.length >= 2){    Config.prnt_dbg_msg(values[0] + "\t" + values[1]);    if (values[0].equalsIgnoreCase("debug_mode"))         debug_mode = isTrue(values[1]);    if (values[0].equalsIgnoreCase("debug_query_parsing"))         debug_query_parsing = isTrue(values[1]);    if (values[0].equalsIgnoreCase("username"))         Connection_Manager.alterAccessParameters(values[1], null, null);    if (values[0].equalsIgnoreCase("password"))         Connection_Manager.alterAccessParameters(null, values[1], null);if (values[0].equalsIgnoreCase("database"))         Connection_Manager.alterAccessParameters(null, null, values[1]);    if (values[0].equalsIgnoreCase("allow_duplicate_entries"))         allow_duplicate_entries = isTrue(values[1]);}

我尝试使用value[0].equal("debug_mode")并获得了相同的结果。有人知道为什么吗?

答案1

小编典典

确实那将是非常奇怪的:)您可以将上面的代码更改为此:

if ("debug_mode".equalsIgnoreCase("debug_mode"))     debug_mode = true;

确认它工作正常,然后再次检查为什么您values[0]不是“ debug_mode”。

这就是我现在要检查的事情清单:

  • 检查一下 values[0].length() == "debug_mode".length()
  • 我非常怀疑,但是无论如何我还是要把它放在桌子上-您是否有机会使用Unicode?
  • 您可以打印每个字符并.equals()在该字符和“ debug_mode”字符串的各个字符之间执行操作吗?
  • 如果这是在较大的项目中,则您可以在一个简单的Java项目中执行相同的操作并确认它可以在其中工作吗?

为了澄清,问题实际上是在使用DataInputStream.readLine。从javadoc(http://download.oracle.com/javase/1.6.0/docs/api/java/io/DataInputStream.html):

readLine()      Deprecated. This method does not properly convert bytes to characters. ...

它实际上以一种微妙的方式与Unicode有关-当writeChar您实际编写两个字节0以及97字母的大端Unicode时a

这是一个独立的片段,显示了行为:

import java.io.*;import java.util.*;public class B {  public static void main(String[] args) throws Exception {    String os = "abc";    System.out.println("---- unicode, big-endian");    for(byte b: os.getBytes("UTF-16BE")) {      System.out.println(b);    }    ByteArrayOutputStream baos = new ByteArrayOutputStream();    DataOutputStream dos = new DataOutputStream(baos);    for(char c: os.toCharArray()) {      dos.writeChar(c);    }    byte[] ba = baos.toByteArray();    System.out.println("---- ba");    for(byte b: ba) {      System.out.println(b);    }    ByteArrayInputStream bais = new ByteArrayInputStream(ba);    DataInputStream dis = new DataInputStream(bais);    System.out.println("---- dis");    String s = dis.readLine();    System.out.println(s);    System.out.println("String length is " + s.length()       + ", but you would expect " + os.length()       + ", as that is what you see printed...");  }}

故事的寓意-不要使用不推荐使用的API
…而且,空格是无声的杀手:http : //www.codinghorror.com/blog/2009/11/whitespace-the-
silent-killer.html

Excel-单元格包含列表中的值-返回列表值,但避免返回不正确的值

Excel-单元格包含列表中的值-返回列表值,但避免返回不正确的值

做两件事将解决屏幕快照中的所有错误:

  1. 使用FIND()(区分大小写)而不是SEARCH(不区分大小写)。这样可以修复Alva和Stow错误。
  2. 将位置关键字从最长到最短排序。由于您的公式返回了第一个匹配项,因此,如果“字符串”列中有“墨尔本港”,则墨尔本港将优先于墨尔本。

但是,这不能解决“ Stowage Alva”或“ Stow Alvan”之类的问题。为此,我们假定您的位置关键字始终在前面或后面加上空格,或两者都在前面(因为所有标点符号都已预先删除)。我们可以通过将公式中的 ISNUMBER(SEARCH($F$2:$F$9,A2))替换为以下两种情况来检查这两种情况:

ISNUMBER(1/(IFERROR(FIND(" "&$F$2:$F$9,A2),0)+IFERROR(FIND($F$2:$F$9&" ",0)))

MATCH(TRUE,INDEX(ISNUMBER(SEARCH($F$2:$F$9,A2)),),0)在您的公式中,并带有:

MATCH(1,ISNUMBER(FIND(" "&$F$2:$F$9&" ",A2))+(LEFT(A2,LEN($F$2:$F$9))=$F$2:$F$9)*ISNUMBER(FIND($F$2:$F$9&" ",A2))+(RIGHT(A2,LEN($F$2:$F$9))=$F$2:$F$9)*ISNUMBER(FIND(" "&$F$2:$F$9,0)

我们今天的关于model.evaluate对于同一度量返回不同的值,具体取决于是以损失还是度量形式返回的分享就到这里,谢谢您的阅读,如果想了解更多关于C 输出不符合预期 - 全局变量返回不同的值、Dart / Flutter按位移位运算符返回不同的值、equal()和equalsIgnoreCase()对于相等的字符串返回false、Excel-单元格包含列表中的值-返回列表值,但避免返回不正确的值的相关信息,可以在本站进行搜索。

本文标签: