哈夫曼编码

文章提出了用于基于卷积神经网络(CNNs)的面部地标定位的新损失函数——修正翼损失(RWing)。通过对不同损失函数的系统分析,研究发现应更加关注小到中等误差的训练。新设计的分段损失函数放大了这些误差的影响,并修正极小误差的损失函数以减轻手动标注不准确的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

请为下面这段英文文本构造哈夫曼编码:
“Effificient and robust facial landmark localisation is crucial for the deployment of real-time face analysis systems. This paper presents a new loss function, namely Rectifified Wing (RWing) loss, for regression-based facial landmark localisation with Convolutional Neural Networks (CNNs). We fifirst systemically analyse different loss functions, including L2, L1 and smooth L1. The analysis suggests that the training of a network should pay more attention to small-medium errors. Motivated by this finding, we design a piece-wise loss that amplififies the impact of the samples with small-medium errors. Besides, we rectify the loss function for very small errors to mitigate the impact of inaccuracy of manual annotation”
要求如下:
1)请计算出每个字符出现的概率,并以概率为权重来构造哈夫曼树,写出构造过程、画出 最终的哈夫曼树,得到每个字符的哈夫曼编码。
2)请将上述设计哈夫曼编码的过程,用代码来实现,并输出各个字母的哈夫曼编码。(有代码,有运行结果的截图)
3)请分析算法的效率,至少包括时间复杂度和空间复杂度等。

2、完成一部电影需要很多环节,具体环节如下:
a:项目启动到确定导演需要1个时间,已确定导演到完善细节需要2个时间,已经完善细节到开始拍摄需要2个时间。
b:项目启动到确定演员需要3个时间,已确定导演到已确定演员需要1个时间,已确定演员到开始拍摄需要2个时间。
c:项目启动到完成场地确认需要5个时间,完成演员确定到完成场地确认需要1个时间,完成场地确认到完善细节需要1个时间,完成场地确认到开始拍摄需要2个时间。
请编写算法,计算出从项目启动到开始拍摄之间至少需要多少个时间?
要求:
1)请画出AOE图,找出关键路径,计算出从项目启动到开始拍摄之间至少需要多少个时间。
2)请将您的思路用代码来实现,并输出关键路径,以及计算出从项目启动到开始拍摄之间至少需要多少个时间。
3)请分析算法的效率,如时间复杂度和空间复杂度等。


#include<stdio.h>
#include<string.h>
#include<stdlib.h> 
#include<windows.h>
typedef int Status;
#define MAXSIZE 100
#define LIST_INIT_SIZE 100
#define OK 1

typedef struct hnode/*定义二叉树的存储结点*/
{ 
	//char name;
	int weight;
   int lchild,rchild,parent;
 }HTNode,*HuffmanTree;
 
typedef char **HuffmanCode;

typedef struct//定义统计字符个数结构//
{
	char name;//字符 
	int num;//出现次数 
}ElemType;

typedef struct
 {
 	ElemType *elem;
 	int length;//当前长 
 	int listsize;//总长 
  } SqList;
   
  Status InitList_Sq(SqList *L)//初始化顺序表 
  {
  	L->elem=(ElemType*)//声明类型 
  	malloc(LIST_INIT_SIZE*sizeof(ElemType));//开辟空间 
  	if (L->elem==NULL)
  		return 0;
	L->length=0;
	L->listsize=LIST_INIT_SIZE;
	return OK;
  }
  Status Search(SqList L,char name)//查找原来表中是否已经有当前统计字符 
{
	int i; 
	for(i=0;i<=L.length;i++)
	{
		if(L.elem[i].name==name)
		{
			return i;//存在返回地址下标 
			break; 
		}
		else if(i==L.length)
		{
			return -1; //不存在返回标志-1 
		}
	}
}
void PrintList(HuffmanCode HC,SqList L,int m)//输出 
{
	int k=L.length;
	for(int i=0;i<k;i++)
	{
		printf("字符:  %c   出现次数:%d    概率:%d/%d    编码:%s\n",L.elem[i].name,L.elem[i].num,L.elem[i].num,m,HC[i+1]);
	}
	//printf("\n\n");
}
void InsertSort(SqList *L)//直接插入排序,以权值的大小升序 
{
    int i,j;
    for(i=1;i<L->length;++i)
    {
        if(L->elem[i].num<L->elem[i-1].num)
        {
            L->elem[-1]=L->elem[i];
            L->elem[i]=L->elem[i-1];
            for(j=i-2;L->elem[-1].num<L->elem[j].num;--j)
            {
                L->elem[j+1]=L->elem[j];
            }
            L->elem[j+1]=L->elem[-1];//插入准确位置 
        }
         
    }
}
void Select(HTNode HT[],int len,int &s1,int &s2)//选出权值最小的两个结点,下标通过s1和s2传出去
{
    int i,min1=32767,min2=32767;
    for(i=1;i<=len;i++)
    {
        if(HT[i].weight<min1&&HT[i].parent==0)
        {
            s2=s1;
            min2=min1;
            min1=HT[i].weight;
            s1=i;
        }
        else if(HT[i].weight<min2&&HT[i].parent==0)
        {    min2=HT[i].weight;
            s2=i;
        }
    }
}
void CreateHuffman_tree(SqList L,HuffmanTree &HT,int n)/*建立n个叶子结点的哈夫曼树*/
{
    //if (n<=1) return 0;
    int m,i,s1,s2;
    m=2*n-1;
    HT=(HuffmanTree)malloc((m+1)*sizeof(HTNode));
    for(i=1;i<=n;i++)
    {
        //scanf("%d",&HT[i].weight);
        //HT[i].name=L.elem[i-1].name;
        HT[i].weight=L.elem[i-1].num;
        HT[i].parent=0;
        HT[i].lchild=0;
        HT[i].rchild=0;
    }
    for ( ;i<=m;++i)
    {
        HT[i].parent=0;
        HT[i].lchild=0;
        HT[i].rchild=0;
    }
    for (i=n+1;i<=m;++i)
    {
        Select(HT,i-1,s1,s2);
        HT[s1].parent=i;
        HT[s2].parent=i;
        HT[i].lchild=s1;
        HT[i].rchild=s2;
        HT[i].weight=HT[s1].weight+HT[s2].weight;
    }
    
}
void Huffman_code(HuffmanTree HT,HuffmanCode &HC,int n)//求哈夫曼编码
{
	char *cd;
	int i,start,c,f;
    cd=(char*)malloc(n*sizeof(char));
    cd[n-1]='\0';
    HC=(HuffmanCode)malloc((n+1)*sizeof(char*));
    for(i=1;i<=n;++i)
    {
        start=n-1;
        c=i;
        f=HT[i].parent;
        while(f!=0)
        {
            --start;
            if(HT[f].lchild==c) cd[start]='0';
            else cd[start]='1';
            c=f;
            f=HT[f].parent;
            
        }//while
        HC[i]=(char*)malloc((n-start)*sizeof(char));
        strcpy(HC[i],&cd[start]);
    }
    free(cd);
}
int main()
{
	int i,k,d,j=0;
	SqList L;//定义一个顺序表,存储统计的字符 
	InitList_Sq(&L);
	char str[]="Effificient and robust facial landmark localisation is crucial for the deployment of real-time face analysis systems. This paper presents a new loss function, namely Rectifified Wing (RWing) loss, for regression-based facial landmark localisation with Convolutional Neural Networks (CNNs). We fifirst systemically analyse different loss functions, including L2, L1 and smooth L1. The analysis suggests that the training of a network should pay more attention to small-medium errors. Motivated by this finding, we design a piece-wise loss that amplififies the impact of the samples with small-medium errors. Besides, we rectify the loss function for very small errors to mitigate the impact of inaccuracy of manual annotation";
	printf("原字符串:%s\n\n",str);
	k=strlen(str);//计算原字符串的长度 
	printf("字符串长度:%d\n",k);
	for(i=0;i<k;i++)
	{
		if(Search(L,str[i])==-1)//还未有统计该字符,开辟一个单元 
		{
			j=L.length;
			L.elem[j].name=str[i];
			L.elem[j].num=1;//放入该字符,数量定位1 
			L.length++;//表长增加 
		}
		else
		{
			d=Search(L,str[i]);//已经统计过,加一处理 
			L.elem[d].num=L.elem[d].num+1;
		}
	}
	printf("总字符数:%d\n",L.length);
	InsertSort(&L);
	 
	
	//进行哈夫曼编码 
	
	
	HuffmanTree HT;
    HuffmanCode HC;
    //int i, n;
    //scanf("%d",&n);
    CreateHuffman_tree(L,HT, L.length);/*建立哈夫曼树*/
    Huffman_code(HT,HC,L.length);/*哈夫曼树编码*/
    
    
    PrintList(HC,L,k);//按权重排序后输出统计结果和编码 
	return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恶心猫charming

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值