2016 Multi-University Training Contest 2 hdu 5734 Acperience【推公式,数学】

本文探讨了在资源受限设备上应用卷积神经网络(CNN)的问题,通过权重二值化来简化网络结构,降低计算复杂度。文章提供了一种找到最佳二值权重和缩放因子的方法,并附带了解题思路及AC代码。

Acperience

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 120    Accepted Submission(s): 56

Problem Description

Deep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular type of DNN, known as Convolutional Neural Networks (CNN), have demonstrated state-of-the-art results in object recognition and detection.

Convolutional neural networks show reliable results on object recognition and detection that are useful in real world applications. Concurrent to the recent progress in recognition, interesting advancements have been happening in virtual reality (VR by Oculus), augmented reality (AR by HoloLens), and smart wearable devices. Putting these two pieces together, we argue that it is the right time to equip smart portable devices with the power of state-of-the-art recognition systems. However, CNN-based recognition systems need large amounts of memory and computational power. While they perform well on expensive, GPU-based machines, they are often unsuitable for smaller devices like cell phones and embedded electronics.

In order to simplify the networks, Professor Zhang tries to introduce simple, efficient, and accurate approximations to CNNs by binarizing the weights. Professor Zhang needs your help.

More specifically, you are given a weighted vector W=(w1,w2,...,wn). Professor Zhang would like to find a binary vector B=(b1,b2,...,bn) (bi∈{+1,−1})and a scaling factor α≥0 in such a manner that ∥W−αB∥2 is minimum.

Note that ∥⋅∥ denotes the Euclidean norm (i.e. ∥X∥=x21+⋯+x2n−−−−−−−−−−√, where X=(x1,x2,...,xn)).

 

 

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integers n (1≤n≤100000) -- the length of the vector. The next line contains n integers: w1,w2,...,wn (−10000≤wi≤10000).

 

 

Output

For each test case, output the minimum value of ∥W−αB∥2 as an irreducible fraction "p/q" where p, q are integers, q>0.

Sample Input

3

4

1 2 3 4

4

2 2 2 2

5

5 6 2 3 4

Sample Output

5/1

0/1

10/1

Author

zimpha

 

 题目大意:


给你一个向量W=(W1,W2,W3.......)【wi的值取决于输入】,然后再给你一个向量B=(B1,B2,B3...........)【Bi的值要么是+1,要么是-1】,令W-αB得到的向量摸方值最小,问这个最小值,并且用分数表示(当然是要不可约分的数)。 


思路:


1、这个题挺坑的,一开始如果想错了,那么每一步都想错了,而且这个题真的很容易把我们带入求平均值从而得到值α的路上去,很可惜,这个思路是错的。


2、观察式子以及推导过程:

①(W1-αB1)^2+(W2-αB2)^2+(W2-αB2)^2+..............

②将上述式子展开:n*α^2+Σ(i=1,i=n)【Wi*2】α+Σ(i=1,i=n)【Wi^2】;

③我们不妨将上式子看成一元二次方程组:aα^2+bα+c,其中a=n,b=Σ(i=1,i=n)【Wi*2】,c=Σ(i=1,i=n)【Wi^2】

④因为n是一定大于0的,所以这个抛物线在直角坐标系中一定是开口向上的,那么其最小值也一定在对称轴-b/2*a上, 那么我们将对称轴作为α的值带回原式。

⑤其解ans=4*a*c-b^2/4a


3、输出ans。注意负Wi


Ac代码:


#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
ll aa[101010];
ll gcd(ll x,ll y)
{
    if(x%y==0)return y;
    else return gcd(y,x%y);
}
ll abs(ll tmp)
{
    if(tmp<0)return -tmp;
    else return tmp;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        ll a,b,c;
        a=n;
        b=0;
        c=0;
        for(int i=0;i<n;i++)
        {
            scanf("%I64d",&aa[i]);
            aa[i]=abs(aa[i]);
            b+=2*aa[i];
            c+=aa[i]*aa[i];
        }
        ll fenzi=4*a*c-b*b;
        ll fenmu=4*a;
        if(fenzi==0)printf("0/1\n");
        else
        printf("%I64d/%I64d\n",fenzi/gcd(fenzi,fenmu),fenmu/gcd(fenzi,fenmu));
    }
}


基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值