Blog Archive

Friday, January 27, 2017

谷歌CEO皮查伊:语音搜索是最自然的交互 我们优势明显 - 未名空间(mitbbs.com)

谷歌CEO皮查伊:语音搜索是最自然的交互 我们优势明显 - 未名空间(mitbbs.com):



编者按:在人工智能和网络搜索领域,谷歌一直有自己强大的优势,只要能将这两项技术相结合,搜索巨人在语音搜索领域必然也能有所作为。不过,如果谷歌不能将Assistant交到用户手中,它们在语音搜索领域的优势也就成了空中楼阁



在Alphabet第四季财报电话会议上,一位分析师就表达了类似的担忧,他想知道谷歌是如何为自家的语音搜索产品开拓市场的。Mitbbs.com


在财报会议上,加拿大皇家银行分析师马克·马汉尼表示,鉴于硬件不是谷歌的核心业务,如果它们未来对该业务丧失信心,语音搜索业务将面临巨大挑战。“与亚马逊Alexa和苹果Siri相比,谷歌的硬件产品销量都较为一般,它们的语音搜索怎么扩大占有率呢?”Mitbbs.com


谷歌CEO皮查伊回应称:“语音搜索行业的竞争才刚刚开始,谷歌肯定不会掉队。”Mitbbs.com


“谷歌看好语音搜索的未来,我认为这是最自然的用户交互方式。”皮查伊说道。Mitbbs.com


其实皮查伊已经为语音搜索定下了新战略,未来Assistant语音助手将从安卓手机平台扩展至智能家居、电视和汽车等产品。“我们想让用户意识到,谷歌语音搜索能随叫随到。”Mitbbs.com


皮查伊强调称,Google Home音箱上市首季销售非常强劲(并未公布销量数字)。此外,尽管谷歌在自然语言处理上走在业界前列,但要想为用户提供更棒的体验,它们还有许多工作要做。Mitbbs.com


J.P.摩根公司分析师道格拉斯·安慕斯则更关心谷歌如何将语音搜索变现。不过,财大气粗的谷歌并不着急,语音搜索是否能在短期内盈利不重要。Mitbbs.com


皮查伊称,语音搜索是谷歌搜索生态系统的一部分,只要语音搜索有足够用户,这一生态系统就会不断壮大。Mitbbs.com


“在思考关于语音搜索的问题时,我发现该领域的机遇远大于挑战。”皮查伊说道M


'via Blog this'

Sunday, January 22, 2017

Count Inversions in an array | Set 1 (Using Merge Sort) - GeeksforGeeks

Count Inversions in an array | Set 1 (Using Merge Sort) - GeeksforGeeks: "include "





#include <stdio.h>

#include <stdlib.h>

#include <iostream>

#include <fstream>

#include<vector>

#include<string>

using namespace std;

//#include<iostream>



unsigned int _mergeSort(int arr[], int tmp[], int beg, int end);

unsigned int merge(int arr[], int tmp[], int beg, int mid, int end);





unsigned int mergeSort(int arr[], int n){

    int *tmp= (int *) malloc (sizeof(int)*n);

    return _mergeSort(arr, tmp, 0,  n - 1);

}



unsigned int _mergeSort(int arr[], int tmp[], int beg, int end){

    int mid;

    unsigned int invCnt = 0;

//    if (end - beg  < 2) return 0;

    if(beg < end){

        mid = beg + (end - beg)/2;

        invCnt += _mergeSort(arr, tmp, beg,     mid);

        invCnt += _mergeSort(arr, tmp, mid + 1, end);

        invCnt += merge(arr,tmp,beg,mid + 1,end);

    }

    return invCnt;

}



unsigned int merge(int arr[], int tmp[], int beg, int mid, int end){

    unsigned int invCnt = 0;

    int i = beg;

    int j = mid;

    int k = beg;

    while(i <= mid-1 && j <= end){

        if( arr[i] < arr[j])

            tmp[k++] = arr[i++];

        else{

            tmp[k++] = arr[j++];

            invCnt += (mid-1) - i + 1;

        }

    }

   

    while(i <= mid-1)

        tmp[k++] = arr[i++];

    while(j <= end)

        tmp[k++] = arr[j++];

    for(int i = beg; i <= end; ++i)

        arr[i] = tmp[i];

    return invCnt;

}





int main() {

//code

int arr[]={2, 4, 1, 3, 5};

int n = sizeof(arr)/sizeof(arr[0]);

unsigned int cnt = mergeSort(arr,n);

printf(" Number of inversions are %d \n", cnt);

ifstream inputFile("IntegerArray.txt");

//ifstream inputFile("IntegerArray0.txt");

string line;

vector<int> ivec;

if(inputFile.is_open()){

while(getline(inputFile, line))

ivec.push_back(stoi(line));

           inputFile.close();

}



cout<<"number of item="<<ivec.size()<<endl;

int *p = new int[ivec.size()];

        //int p[100000];

        for(int i =0; i < ivec.size(); ++i)

p[i]=ivec[i];

        cnt = mergeSort(p, ivec.size());

printf(" 2: Number of inversions are %d \n", cnt);

unsigned int key=2407905288;

cout<<"cnt="<<cnt << " key shoud be : 2407905288 ="<< key <<endl;

        delete [] p;

return 0;

}



'via Blog this'

Count Inversions in an array | Set 1 (Using Merge Sort) - GeeksforGeeks

Count Inversions in an array | Set 1 (Using Merge Sort) - GeeksforGeeks: "printf(" Number of inversions are %d \n", getInvCount(arr, n));"



'via Blog this'

Algs4-1.4.18 Find local minimum in n x n matrix in O(n) time - vmxplus的博客 - 博客频道 - CSDN.NET

Algs4-1.4.18 Find local minimum in n x n matrix in O(n) time - vmxplus的博客 - 博客频道 - CSDN.NET: "Algs4-1.4.18 Find local minimum in n x n matrix in O(n) time"



Question:
You are given an n by n grid of distinct numbers. A number is a local minimum if it is smaller than all of its neighbors. (A neighbor of a number is one immediately above, below, to the left, or the right. Most numbers have four neighbors; numbers on the side have three; the four corners have two.) Use the divide-and-conquer algorithm design paradigm to compute a local minimum with only O(n) comparisons between pairs of numbers. (Note: since there are n2 numbers in the input, you cannot afford to look at all of them. Hint: Think about what types of recurrences would give you the desired upper bound.)

Soultion:
We can adapt Words Like Jared's answer, by looking at how it can Go wrong.
The idea in that answer -- which is a good one -- is to "roll downhill". This just means, if you are on an element, check if it is a local minimum. If so, you are done; otherwise, step to the smallest of its nearest neighbors. Eventually this must terminate because every step is to a smaller element, and that cannot go on forever in a finite array.
The problem with this approach is that the "rolling" can meander all over the place:
20 100 12  11 10 100  2
19 100 13 100  9 100  3
18 100 14 100  8 100  4
17  16 15 100  7   6  5
If you start at the upper left and "roll downhill", you will visit around half of the elements in the array. That is too many, so we have to constrain it a bit.
Start by examining the middle column and middle row. Find the smallest element among all of those and start there.
Roll one step "downhill" from there to enter one of the four quadrants. You will enter one of the quadrants, because the adjacent elements in the middle column and/or row are larger, so only one of the two adjacent quadrants could be "downhill".
Now consider what would happen if you "rolled downhill" from there. Obviously, you would eventually reach a local minimum. (We will not actually do this because it would take too long.) But, in the course of rolling around, you would never leave that quadrant... Because to do so, you would have to cross either the middle column or middle row, and none of those elements are smaller than where you started. Therefore that quadrant contains a local minimum somewhere.
Thus, in linear time, we have identified a quadrant that must contain a local minimum, and we have cut n in half. Now just recurse.
This algorithm takes time 2n + 2n/2 + 2n/4 + ..., which equals 4n, which is O(n) so we are done.
Interestingly, we did not use "rolling downhill" very much at all, except for the critical part: Proving that the algorithm works.
[Update]
As Incassator points out, this answer is not entirely correct, because after you "just recurse" you might roll out of the quadrant again...
The simplest fix is to find the smallest element among the middle row, middle column, and boundarybefore you "roll downhill".

Author:  Nemo
Supplement:
The accepted answer by Nemo is nice but not fully correct:
Thus, in linear time, we have identified a quadrant that must contain a local minimum, and we have cut n in half. Now just recurse.
I am referring to "just recurse" bit. The problem is we cannot do that directly because on next iteration we might find a local minimum which is not a local minimum for original grid (x below means some arbitrary large numbers):
 x  x 39  x  x 50  x  x  x  x  x
 x  x 38  x  x 49  x  x  x  x  x
37 36 33 34 35 48  x  x  x  x  x
 x  x 32  x  1 10  x  x  x  x  x
 x  x 31  x  x 47  x  x  x  x  x
46 45 30 44 43 60 51 52 53 54 55
 x  x  2  x  x 56  x  x  x  x  x
 x  x  x  x  x 57  x  x  x  x  x
 x  x  x  x  x 58  x  x  x  x  x
 x  x  x  x  x 59  x  x  x  x  x
At first iteration we find 10 to be a minimum of middle row and middle column. We go to the left (as 1 is less than 10). So our next iteration is on upper-left quadrant. But now minimum of middle row and column is going to be 31 (or 30 if quadrant's borders are considered to be part of it). You will then conclude that it is a local minimum. But it is not for the full grid.
We can rectify this unfortunate defect in variety of ways. I solved it like this:
At each iteration in addition to the grid itself we keep track of current minimum candidate (that is the 1 in the example above after first iteration; in the initial state we can say minimum candidate is plus infinity). We calculate minimum of middle row and column and compare it to minimum candidate. If the latter is smaller we recurse into the quadrant containing minimum candidate. Otherwise we forget previous candidate and only then check whether new middle row/column minimum is actually a local minimum. And if not then recurse as usual to whatever quadrant we slope down from it (and track new minimum candidate).
Alternatively, you can modify the procedure as described in this presumably MIT lecture: at each iteration instead of looking at middle row/column you can look at middle row/column and grid boundary. Then the algorithm once again is correct.
You choose which way you like.
Author: Incassator



Ref:  http://stackoverflow.com/questions/18525179/find-local-minimum-in-n-x-n-matrix-in-on-time

理财不理财,差距究竟有多大? - 未名空间(mitbbs.com)

理财不理财,差距究竟有多大? - 未名空间(mitbbs.com): "www.fengjr.u"



'via Blog this'